<?php
/*
Generated by OutputBooks Team
*/

class OrderParser
{
    public $message = '';
    public $trans;
    public $ecTrans;
    public $ci = null;
    public $db = null;
    function __construct($params)
    {
        goto tk4bV;
        svp5j:
        if (empty($params["\x63\x49\144"]) || empty($params["\142\111\x64"])) {
            throw new Exception("\103\157\155\x70\141\156\x79\x20\155\x69\x73\x73\x69\156\147\x2e");
            return;
        }
        goto WE1JI;
        WE1JI:
        $this->trans->cId = $params["\x63\111\144"];
        goto AW9qZ;
        uxBWj:
        $this->ci =& get_instance();
        goto Hnf2W;
        tk4bV:
        $this->trans = new stdClass();
        goto JgJgl;
        JgJgl:
        $this->ecTrans = new stdClass();
        goto svp5j;
        AW9qZ:
        $this->trans->bId = $params["\142\x49\144"];
        goto uxBWj;
        Hnf2W:
        $this->db =& $this->ci->db;
        goto q4a3S;
        q4a3S:
    }
    public function parse($data = array())
    {
        goto i8T2K;
        wRNet:
        $this->trans->conName = '';
        goto raeO1;
        EM6TX:
        $this->applyDetails();
        goto vBJYX;
        LSwfe:
        return $this->trans;
        goto Mi7rf;
        IEA6p:
        $this->trans->conLocCode = "\x49";
        goto cj_zO;
        hJP1o:
        $this->applyPayment();
        goto LSwfe;
        cj_zO:
        $this->trans->conTaxNo = '';
        goto v0p3B;
        raeO1:
        $this->trans->conStateId = '';
        goto OMhjY;
        gr5S4:
        $this->trans->dstStateId = get_company("\163\x74\x61\x74\145\111\144");
        goto So0W_;
        v0p3B:
        $this->trans->conTaxScheme = "\x55";
        goto fiNbC;
        OMhjY:
        $this->trans->conStateCode = '';
        goto IEA6p;
        i8T2K:
        if (!empty($data)) {
            goto XkhhS;
            r_163:
            $this->trans->tax = $data["\x74\141\170"];
            goto Rf1iF;
            vxd2r:
            $this->trans->billingAddr = $data["\142\151\x6c\154\151\x6e\147\x41\x64\144\x72"];
            goto tx6MN;
            T38_6:
            $this->trans->email = $data["\145\x6d\x61\151\154"];
            goto PV8BH;
            fUt2n:
            $this->trans->tDate = $data["\164\x44\x61\x74\145"];
            goto WFvkI;
            wdeco:
            $this->trans->subTotalAmount = $data["\163\165\142\x54\x6f\x74\141\154\x41\155\157\165\x6e\164"];
            goto H0IZw;
            Dm0Mi:
            $this->trans->source = $data["\163\157\165\x72\x63\x65"];
            goto T38_6;
            H0IZw:
            $this->trans->shipping = $data["\x73\150\x69\160\x70\x69\x6e\x67"];
            goto db824;
            WFvkI:
            $this->trans->tType = $data["\164\x54\x79\x70\145"];
            goto alkgt;
            MhVxW:
            $this->trans->address = $data["\x61\144\x64\162\x65\x73\x73"];
            goto vPoID;
            XkhhS:
            $this->trans->id = $data["\x69\144"];
            goto TIMP_;
            tx6MN:
            $this->trans->shippingAddr = $data["\163\x68\x69\160\160\151\156\147\x41\x64\144\162"];
            goto i94xw;
            vPoID:
            $this->trans->details = $data["\144\x65\x74\141\151\154\x73"];
            goto r_163;
            db824:
            $this->trans->payment = $data["\x70\x61\x79\x6d\x65\156\x74"];
            goto MhVxW;
            alkgt:
            $this->trans->conName = $data["\x63\157\x6e\x4e\x61\155\x65"];
            goto SrGww;
            SrGww:
            $this->trans->totAmount = $data["\x74\157\164\101\x6d\x6f\x75\156\164"];
            goto Dm0Mi;
            TIMP_:
            $this->trans->tNo = $data["\x74\116\157"];
            goto fUt2n;
            PV8BH:
            $this->trans->mobile = $data["\x6d\157\142\151\x6c\x65"];
            goto wdeco;
            Rf1iF:
            $this->trans->contact = $data["\143\157\x6e\164\x61\x63\x74"];
            goto vxd2r;
            i94xw:
        }
        goto f7zUp;
        XlB5t:
        $this->applyContact();
        goto EM6TX;
        So0W_:
        $this->trans->totTax = 0;
        goto XlB5t;
        vBJYX:
        $this->applyTax();
        goto hJP1o;
        fiNbC:
        $this->trans->dstStateCode = get_company("\x73\x74\141\164\x65\x43\x6f\144\145");
        goto gr5S4;
        f7zUp:
        $this->trans->conId = '';
        goto wRNet;
        Mi7rf:
    }
    function mapKeys($data, $mapFields)
    {
        goto nPw72;
        wCLvH:
        foreach ($mapFields as $key => $val) {
            $return[$val] = !empty($data[$key]) ? $data[$key] : '';
            CVDO4:
        }
        goto o3sup;
        o3sup:
        qwHND:
        goto UFsrJ;
        nPw72:
        $return = array();
        goto wCLvH;
        UFsrJ:
        return $return;
        goto wvwqs;
        wvwqs:
    }
    function applyContact()
    {
        goto ZwJ8y;
        UQOA1:
        $this->db->from("\x63\x6f\x6e\164\141\x63\164\x73");
        goto sEW9t;
        kNBk5:
        return true;
        goto vvyKT;
        DblCy:
        $this->trans->dstStateCode = get_company("\x73\164\x61\164\x65\x43\x6f\x64\x65");
        goto WxYes;
        flhXg:
        if ($this->trans->dstStateCode == $this->trans->conStateCode) {
            $this->trans->conLocCode = "\111";
        } else {
            $this->trans->conLocCode = "\x58";
        }
        goto kNBk5;
        hKvMr:
        if (!empty($this->trans->shippingAddr)) {
            $state = $this->get_state(array("\143\x6f\x75\x6e\164\x72\x79\x43\157\144\145" => $this->trans->shippingAddr["\143\x6f\x75\x6e\x74\x72\x79\103\157\x64\x65"], "\x73\x74\141\x74\x65\x43\x6f\x64\145" => $this->trans->shippingAddr["\163\x74\x61\x74\x65\103\157\144\145"]));
            if (!empty($state)) {
                $this->trans->shippingAddr["\163\x74\141\164\x65\x49\x64"] = $state["\x69\144"];
            }
        }
        goto DblCy;
        s1FJq:
        $contact = $this->db->get()->result_array();
        goto yk9nA;
        bjOQ9:
        if (!empty($this->trans->billingAddr)) {
            $state = $this->get_state(array("\143\157\165\x6e\164\x72\x79\103\x6f\144\x65" => $this->trans->billingAddr["\x63\x6f\x75\156\164\x72\171\x43\157\144\x65"], "\x73\x74\x61\164\x65\x43\x6f\144\145" => $this->trans->billingAddr["\163\x74\141\164\x65\103\x6f\x64\x65"]));
            if (!empty($state)) {
                $this->trans->billingAddr["\163\164\x61\164\x65\111\144"] = $state["\x69\144"];
            }
        }
        goto hKvMr;
        ZwJ8y:
        $this->db->select("\x2a");
        goto UQOA1;
        sEW9t:
        $this->db->where(array("\143\111\144" => $this->trans->cId));
        goto y1lOc;
        WxYes:
        $this->trans->dstStateId = get_company("\163\164\141\164\145\x49\x64");
        goto flhXg;
        yk9nA:
        if (!empty($contact) && !empty($contact[0])) {
            goto F13EX;
            LKIoJ:
            $this->trans->conId = $contact["\x69\144"];
            goto u8d2u;
            xK2Bp:
            $this->trans->conTaxScheme = $contact["\x63\157\x6e\x54\141\x78\x53\x63\150\x65\155\145"];
            goto cQipU;
            K0Bqx:
            $this->trans->conTaxNo = $contact["\164\141\170\116\157"];
            goto xK2Bp;
            u8d2u:
            $this->trans->contact["\x73\164\141\164\x65\x49\x64"] = $contact["\163\x74\141\164\x65\111\144"];
            goto S0RS1;
            F13EX:
            $contact = $contact[0];
            goto LKIoJ;
            wybH1:
            $this->trans->conStateCode = $contact["\x73\164\141\x74\x65\103\157\x64\145"];
            goto K0Bqx;
            S0RS1:
            $this->trans->conStateId = $contact["\163\x74\141\x74\145\111\144"];
            goto wybH1;
            cQipU:
        } else {
            goto Uk7Ki;
            mr2dS:
            if (!empty($state)) {
                goto wMES7;
                HsngR:
                $this->trans->conStateCode = $state["\163\164\x61\164\x65\103\x6f\x64\145"];
                goto NukYs;
                XFeBw:
                $this->trans->conStateId = $state["\151\144"];
                goto HsngR;
                wMES7:
                $this->trans->contact["\x73\164\141\164\x65\x49\144"] = $state["\151\x64"];
                goto XFeBw;
                NukYs:
            }
            goto VmEsL;
            Uk7Ki:
            if (strtoupper($this->trans->contact["\x63\x6f\x75\156\164\x72\171\x43\157\x64\145"]) != "\111\116") {
                $this->trans->classCode = "\105\x58\x50\x57\117\120";
            }
            goto z3KdO;
            z3KdO:
            $state = $this->get_state(array("\x63\157\x75\x6e\x74\x72\x79\103\x6f\x64\x65" => $this->trans->contact["\x63\x6f\x75\x6e\x74\162\x79\103\x6f\x64\145"], "\163\164\x61\x74\145\103\x6f\x64\145" => $this->trans->contact["\x73\164\x61\x74\x65\x43\157\x64\145"]));
            goto mr2dS;
            VmEsL:
        }
        goto bjOQ9;
        y1lOc:
        $this->db->like("\x6e\x61\155\x65", $this->trans->conName);
        goto s1FJq;
        vvyKT:
    }
    function applyDetails()
    {
        goto jjrb3;
        uAhkb:
        $this->db->from("\x69\x74\x65\155\163\x20\x41\x53\x20\151");
        goto KHIFv;
        KHIFv:
        $this->db->where(array("\151\56\x63\x49\144" => $this->trans->cId));
        goto YUouu;
        ztu4L:
        $this->db->select("\151\x2e\52");
        goto uAhkb;
        Zmpmy:
        return true;
        goto f7n5t;
        UCdhI:
        if (!empty($itemsArr)) {
            goto x35We;
            MLc9V:
            $itemsArr = $_itemsArr;
            goto kg_ci;
            EL9Aq:
            i_QiP:
            goto MLc9V;
            VWFel:
            foreach ($itemsArr as $val) {
                $_itemsArr[$val["\x53\x4b\125"]] = $val;
                oX98V:
            }
            goto EL9Aq;
            x35We:
            $_itemsArr = array();
            goto VWFel;
            kg_ci:
        }
        goto Gzg6U;
        YUouu:
        $this->db->where_in("\151\56\123\113\125", $sku);
        goto N47Yt;
        FJ6wn:
        $this->trans->includeTax = $isIncludeTax;
        goto bfims;
        jjrb3:
        $details = $this->trans->details;
        goto NoFGA;
        Gzg6U:
        $isIncludeTax = true;
        goto FJ6wn;
        N47Yt:
        $itemsArr = $this->db->get()->result_array();
        goto UCdhI;
        NoFGA:
        $sku = array_column($details, "\163\x6b\165");
        goto ztu4L;
        i7qNI:
        $this->trans->details = $details;
        goto Zmpmy;
        uGntE:
        c50iW:
        goto i7qNI;
        bfims:
        foreach ($details as $key => $item) {
            goto dxLlt;
            Uxwu2:
            KLMcf:
            goto lgOVr;
            b5y7O:
            $details[$key] = $item;
            goto Uxwu2;
            dxLlt:
            if (!empty($itemsArr[$item["\163\153\165"]])) {
                $item["\x69\164\145\155\x49\144"] = $itemsArr[$item["\x73\x6b\x75"]]["\x69\164\x65\155\111\x64"];
            } else {
                $item["\x69\164\x65\x6d\x49\x64"] = 0;
                $item["\165\156\151\x74"] = "\x4e\x4f\123";
            }
            goto YRBgS;
            qXc1f:
            $item["\x74\141\170\141\x62\x6c\145\101\x6d\x6f\x75\156\x74"] = $item["\151\x74\x65\155\124\x6f\x74\x61\154"] = $item["\161\x74\x79"] * $item["\x72\141\164\145"];
            goto SkyeZ;
            YRBgS:
            $this->trans->conLocCode;
            goto wIuVV;
            Im2QI:
            if (!empty($item["\164\x61\170"])) {
                goto VusgV;
                wh2ZW:
                foreach ($taxDetails as $k => $taxDetail) {
                    goto JFpRb;
                    FZOap:
                    $taxDetails[$k] = $taxDetail;
                    goto KTb9p;
                    KTb9p:
                    ZZJv6:
                    goto kwQ7a;
                    JFpRb:
                    $taxDetail["\164\x61\x78\x56\141\x6c\x75\145"] = round($item["\164\x61\170\x61\142\154\145\x41\155\157\x75\x6e\164"] * $taxDetail["\x74\141\x78\x52\x61\x74\145"] / 100, 2);
                    goto FZOap;
                    kwQ7a:
                }
                goto GGmLY;
                bbqU9:
                $item["\x74\x61\170"] = $taxDetails;
                goto t3OqL;
                VusgV:
                $item["\164\141\170\x49\x64"] = $item["\164\141\170"]["\151\x64"];
                goto jDQk5;
                GGmLY:
                irTN_:
                goto bbqU9;
                jmGJH:
                if ($item["\164\141\170\122\141\164\x65"]) {
                    if ($this->trans->includeTax) {
                        $item["\x69\164\x65\x6d\124\x6f\164\x61\x6c"] = $item["\161\164\x79"] * $item["\162\141\164\145"];
                        $item["\x74\x61\x78\x61\x62\x6c\x65\x41\155\x6f\165\156\164"] = round($item["\x69\164\x65\x6d\x54\x6f\164\x61\x6c"] / (1 + $item["\x74\x61\170\122\x61\164\145"] / 100), 2);
                    } else {
                        $item["\164\141\x78\141\142\154\x65\101\x6d\157\165\x6e\x74"] = $item["\161\164\171"] * $item["\x72\x61\164\145"];
                        $item["\x69\164\x65\x6d\x54\157\x74\141\154"] = round($item["\164\x61\170\141\x62\x6c\x65\x41\x6d\x6f\x75\x6e\x74"] * (1 + $item["\x74\141\x78\x52\x61\x74\x65"] / 100), 2);
                    }
                }
                goto wh2ZW;
                jDQk5:
                foreach ($item["\164\x61\170"]["\x64\145\x74\141\151\x6c\163"] as $taxDetail) {
                    if ($taxDetail["\x73\x74\x61\164\145\124\171\160\x65"] == $this->trans->conLocCode) {
                        goto Q7ZnW;
                        PjDdp:
                        $item["\164\x61\x78\122\141\x74\145"] += intval($taxDetail["\164\x61\x78\x52\x61\x74\145"]);
                        goto muoKz;
                        rPXCP:
                        if (empty($item["\164\x61\x78\122\x61\x74\x65"])) {
                            $item["\x74\141\170\122\x61\164\x65"] = 0;
                        }
                        goto PjDdp;
                        Q7ZnW:
                        $taxDetails[] = $taxDetail;
                        goto rPXCP;
                        muoKz:
                    }
                    nqkTv:
                }
                goto Aq97H;
                Aq97H:
                erwxA:
                goto jmGJH;
                t3OqL:
            } else {
                $item["\x74\141\x78\x52\x61\x74\x65"] = 0;
            }
            goto b5y7O;
            wIuVV:
            $taxDetails = array();
            goto qXc1f;
            SkyeZ:
            $item["\x74\141\x78\x41\155\157\165\156\164"] = 0;
            goto Im2QI;
            lgOVr:
        }
        goto uGntE;
        f7n5t:
    }
    function searchTax($taxRate = "\x31\x38")
    {
        goto kJ7Pd;
        QYWch:
        if (!empty($tax)) {
            $tax["\144\145\x74\141\151\x6c\163"] = $taxDetails = $this->db->select("\151\x64\54\40\164\141\x78\x54\x79\160\x65\x43\x6f\x64\x65\54\x20\164\141\x78\122\141\x74\x65\54\40\163\x74\x61\164\145\124\x79\160\145\x2c\40\x74\x61\x78\103\x61\154\143")->from("\x74\141\170\144\x65\x74\141\x69\x6c")->where(array("\143\x49\x64" => $this->trans->cId, "\164\141\170\111\x64" => $tax["\x69\144"]))->get()->result_array();
        }
        goto pgfm0;
        kJ7Pd:
        $tax = $this->db->select("\52")->from("\x74\141\170")->where(array("\143\x49\144" => $this->trans->cId, "\164\141\170\x43\x6f\x64\145" => "\x47\123\x54" . $taxRate))->get()->row_array();
        goto QYWch;
        pgfm0:
        return $tax;
        goto ljaXh;
        ljaXh:
    }
    function applyTax()
    {
        return true;
    }
    function applyPayment()
    {
        return true;
    }
    function get_state($where = array())
    {
        goto TbFr_;
        YiRIi:
        $state = $this->db->get()->row_array();
        goto ApoDK;
        TbFr_:
        $this->db->select("\151\x64\54\40\x6e\x61\x6d\145\54\40\x73\164\141\164\x65\x43\157\x64\x65\54\40\164\151\x6e\103\157\144\x65");
        goto N_bFv;
        N_bFv:
        $this->db->from("\x73\x74\x61\x74\x65\x73");
        goto SBcMW;
        lI_MP:
        $this->db->limit(1);
        goto YiRIi;
        ApoDK:
        return $state;
        goto M4UU9;
        SBcMW:
        if (!empty($where)) {
            $this->db->where($where);
        }
        goto lI_MP;
        M4UU9:
    }
}
