Esempio n. 1
0
        public void UpdateDGV(cls_POSTransaction tran)
        {
            if (cls_globalvariables.ads_url_v == "")
            {
                return;
            }

            dgvProduct.DataSource = null;
            lblTender.Text        = "P 0.00";
            lblChange.Text        = "P 0.00";
            lblORNumber_d.Text    = tran.getORnumber().ToString();
            ctrl_productgrid ctrlprod = new ctrl_productgrid(dgvProduct);

            ctrlprod.set_databinding(tran.get_productlist().get_dtproduct());
            dgvProduct.DataSource = ctrlprod.get_productgrid().DataSource;
            lblTotalAmount.Text   = "P " + tran.get_productlist().get_totalamount().ToString("N2");
            lblItemCount.Text     = tran.get_productlist().get_productlist().Count.ToString();
        }
Esempio n. 2
0
        public int save_transaction(cls_POSTransaction trans)
        {
            string  datetime_d   = trans.getdatetime().ToString("yyyy-MM-dd HH:mm:ss");
            string  branchid     = cls_globalvariables.BranchCode;
            long    salesheadwid = trans.getSyncId();
            long    customerid   = trans.getcustomer().getwid();
            string  customername = trans.getcustomer().getfullname();
            decimal adjust       = trans.getadjust();
            string  seniorno     = trans.getsenior().get_idnumber();
            string  seniorname   = trans.getsenior().get_fullname();
            long    userid       = trans.getclerk().getsyncid();
            long    memberid     = trans.getmember().getSyncId();
            long    checkerid    = trans.getchecker().getsyncid();
            decimal totalamt     = trans.get_productlist().get_totalamount();
            bool    iswholesale  = trans.get_productlist().get_iswholesale();
            bool    isnonvat     = trans.get_productlist().get_isnonvat();
            decimal discount     = trans.getdiscount();
            decimal totalpaidamt = trans.getpayments().get_totalamount();

            decimal t  = trans.get_productlist().get_totalamount();
            decimal t2 = trans.get_productlist().get_totalamount_no_head_discount();
            decimal headDiscountPercentage = (t2 == 0) ? 0 : (t / t2);

            decimal                       cash               = trans.getpayments().get_cash();
            decimal                       mem_points         = trans.getpayments().get_points();
            decimal                       change             = trans.get_changeamount();
            List <cls_cardinfo>           creditcards        = trans.getpayments().get_creditcard();
            List <cls_cardinfo>           debitcards         = trans.getpayments().get_debitcard();
            List <cls_giftcheque>         giftchequesnew     = trans.getpayments().get_giftchequenew();
            List <cls_CustomPaymentsInfo> custompaymentsinfo = trans.getpayments().get_custompayments();
            string        sSQLcd         = "";
            List <string> tempStringList = new List <string>();
            //              DO NOT DELETE
            //            //MEMBER (Priority since it will be run on main branch)
            //            if (trans.getmember().getwid() != 0)
            //            {
            //                List<string> memberTransactionListString = new List<string>();
            //                if (mem_points != 0)
            //                {
            //                    tempStringList = get_next_wid_withlock_main_liststring("memberpointtrans");
            //                    foreach (string str in tempStringList)
            //                        memberTransactionListString.Add(str);
            //                    string sSQLmemberpoint_d = @"UPDATE `memberpointtrans` SET
            //                                            `memberid` = " + trans.getmember().getwid() + @",
            //                                            `branchid` = " + branchid + @",
            //                                            `type` = 3,
            //                                            `referencewid` = " + salesheadwid.ToString() + @",
            //                                            `amount` = " + mem_points + @",
            //                                            `status` = 1,
            //                                            `date` = NOW(),
            //                                            `status` = 1,
            //                                            `datecreated` = NOW(),
            //                                            `lastmodifieddate` = NOW(),
            //                                            `userid` = " + userid + @",
            //                                            `lastmodifiedby` = " + userid + @"
            //                                           WHERE `SyncId` = @syncid_d;";
            //                    memberTransactionListString.Add(sSQLmemberpoint_d);
            //                }
            //                if (trans.getmember().getwid() != 0)
            //                {
            //                    decimal point_earn = trans.get_memberpoint_earn();
            //                    List<string> temp = get_next_wid_withlock_main_liststring("memberpointtrans");
            //                    foreach (string str in temp)
            //                        memberTransactionListString.Add(str);
            //                    string sSQLmemberpoint = @"UPDATE `memberpointtrans` SET
            //                                            `memberid` = " + trans.getmember().getwid() + @",
            //                                            `branchid` = " + branchid + @",
            //                                            `type` = 1,
            //                                            `referencewid` = " + salesheadwid.ToString() + @",
            //                                            `amount` = " + point_earn.ToString("N2") + @",
            //                                            `status` = 1,
            //                                            `date` = NOW(),
            //                                            `datecreated` = NOW(),
            //                                            `lastmodifieddate` = NOW(),
            //                                            `userid` = " + userid + @",
            //                                            `lastmodifiedby` = " + userid + @"
            //                                           WHERE `SyncId` = @syncid_d;";
            //                    memberTransactionListString.Add(sSQLmemberpoint);
            //                }
            //                //'select' is purposely lower cased for exec_trans method
            //                memberTransactionListString.Add(@"select 'SUCCESS';");
            //                if (!mySQLFunc.check_connection_main() || exec_trans_main(memberTransactionListString, 3) != "SUCCESS")
            //                    return 1;
            //            }

            string        discquery            = @"";
            List <string> transactionQueryList = new List <string>();
            string        sSQL = "";

            sSQL = @"UPDATE `saleshead` SET
                        `salesman` = " + trans.getsalesman().getsyncid().ToString() + @",
                        `status` = 1, 
                        `customerid` = " + customerid + @", 
                        `customername` = '" + escapeString(customername) + @"',
                        `date` = NOW(),
                        `adjust` = " + adjust + @", 
                        `discount1` = " + discount + @",
                        `seniorno` = '" + seniorno + @"', 
                        `seniorname` = '" + escapeString(seniorname) + @"',
                        `ornumber` = '" + trans.getORnumber() + @"',
                        `userid` = '" + userid + @"',
                        `branchid` = '" + branchid + @"',                     
                        `lastmodifiedby` = " + userid + @", 
                        `lastmodifieddate` = NOW(), 
                        `memberid` = " + memberid + @", 
                        `checkerid` = " + checkerid + @",
                        `iswholesale` = " + iswholesale + @",
                        `isnonvat` = " + isnonvat.ToString() + @"
                        WHERE `SyncId` = " + salesheadwid;

            //Console.WriteLine(sSQL);
            //setdb(sSQL);
            transactionQueryList.Add(sSQL);

            foreach (cls_product prod in trans.get_productlist().get_productlist())
            {
                string qty   = prod.getQty().ToString("G29");
                string price = (prod.getPrice()).ToString();
                string vat   = prod.getVat().ToString();

                cls_user soldby    = (cls_user)prod.getSoldBy();
                long     soldbywid = 0;
                try { soldbywid = soldby.getsyncid(); }
                catch { soldbywid = userid; }

                List <string> temp = GetListStringAndInsertNextSyncId("salesdetail");
                foreach (string str in temp)
                {
                    transactionQueryList.Add(str);
                }
                transactionQueryList.Add("SET @salesdetailwid := @SyncId");
                int    issenior   = (trans.getsenior().get_idnumber().Length >= 1 && prod.getIsSenior() != 0) ? prod.getIsSenior() : 0;
                string sSQLdetail = @"UPDATE `salesdetail` SET
                                `headid` = '" + salesheadwid + @"', 
                                `productid` = '" + prod.getSyncId().ToString() + @"',  
                                `quantity` = '" + qty + @"',   
                                `oprice` = '" + prod.getOrigPrice().ToString() + @"',  
                                `regularDC` = '" + prod.getDiscount().ToString() + @"', 
                                `price` = '" + price + @"',  
                                `pprice` = '" + prod.getPurchasePrice().ToString() + @"', 
                                `vat` = '" + vat + @"',
                                `soldby` = '" + soldbywid + @"',  
                                `memo` = '" + prod.getMemo() + @"'
                            WHERE `SyncId` = @salesdetailwid";
                //Console.WriteLine(sSQLdetail);
                //setdb(sSQLdetail);
                transactionQueryList.Add(sSQLdetail);
            }

            tempStringList = GetListStringAndInsertNextSyncId("collectionhead");
            foreach (string str in tempStringList)
            {
                transactionQueryList.Add(str);
            }
            transactionQueryList.Add(@"SET @collectionheadwid := @syncid_d");
            string sSQLch = @"UPDATE `collectionhead` SET
                                `customerid` = " + customerid + @", 
                                `collectiondate` = NOW(), 
                                `userid` = " + userid + @",  
                                `status` = 1,
                                `branchid` = " + branchid + @", 
                                `lastmodifieddate` = NOW(), 
                                `lastmodifiedby` = " + userid + @", 
                                `datecreated` = NOW(),
                                `memo` = '" + trans.getpayments().get_memo() + @"',
                                `show` = 1
                            WHERE `SyncId` = @collectionheadwid";

            //Console.WriteLine(sSQLch);
            //setdb(sSQLch);
            transactionQueryList.Add(sSQLch);

            string sSQLcs = @"INSERT INTO `collectionsales`
                            (`headid`, `saleswid`, `amount`)
                            VALUES
                            ( @collectionheadwid, " + salesheadwid + ", " + (totalpaidamt - trans.get_changeamount()) + ")";

            //Console.WriteLine(sSQLcs);
            //setdb(sSQLcs);
            transactionQueryList.Add(sSQLcs);

            if (cash != 0)
            {
                tempStringList = GetListStringAndInsertNextSyncId("collectiondetail");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `collectiondetail` SET
                                `headid` = @collectionheadwid,
                                `method` = 1, 
                                `amount` = " + cash + @"
                           WHERE `SyncId` = @syncid_d";

                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
            }

            if (change > 0)
            {
                tempStringList = GetListStringAndInsertNextSyncId("collectiondetail");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `collectiondetail` SET
                                `headid` = @collectionheadwid,
                                `method` = 1,
                                `amount` = -" + change + @"
                           WHERE `SyncId` = @syncid_d";

                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
            }

            foreach (cls_cardinfo creditcard in creditcards)
            {
                tempStringList = GetListStringAndInsertNextSyncId("collectiondetail");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `collectiondetail` SET
                                `headid` = @collectionheadwid,
                                `method` = 5, 
                                `amount` = " + creditcard.getamount() + @"
                           WHERE `SyncId` = @syncid_d";

                //Console.WriteLine(sSQLcd);
                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
                transactionQueryList.Add("SET @collectiondetailwid = @syncid_d");

                tempStringList = GetListStringAndInsertNextSyncId("poscardpayment");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `poscardpayment` SET
                            `collectiondetailid` = @collectiondetailwid, 
                            `cardsettingwid` = '" + cls_globalfunc.getCreditDebiCardInfo(creditcard.getcardno()) + @"', 
                            `cardno` = '" + creditcard.getcardno() + @"', 
                            `fullname` = '" + escapeString(creditcard.getname()) + @"',
                            `expdate` = '" + creditcard.getexpdate().ToString("yyyy-MM-dd") + @"', 
                            `type` = '0', 
                            `approvalcode` = '" + escapeString(creditcard.getapprovalcode()) + @"',
                            `amount` = '" + creditcard.getamount() + @"'
                           WHERE `SyncId` = @syncid_d";
                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
            }

            foreach (cls_cardinfo debitcard in debitcards)
            {
                tempStringList = GetListStringAndInsertNextSyncId("collectiondetail");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `collectiondetail` SET
                                `headid` = @collectionheadwid,
                                `method` = 6, 
                                `amount` = " + debitcard.getamount() + @"
                           WHERE `SyncId` = @syncid_d";

                //Console.WriteLine(sSQLcd);
                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
                transactionQueryList.Add("SET @collectiondetailwid = @syncid_d");

                tempStringList = GetListStringAndInsertNextSyncId("poscardpayment");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `poscardpayment` SET
                            `collectiondetailid` = @collectiondetailwid, 
                            `cardno` = '" + debitcard.getcardno() + @"', 
                            `fullname` = '" + escapeString(debitcard.getname()) + @"',
                            `expdate` = '" + debitcard.getexpdate().ToString("yyyy-MM-dd") + @"', 
                            `type` = '1', 
                            `approvalcode` = '" + escapeString(debitcard.getapprovalcode()) + @"',
                            `amount` = '" + debitcard.getamount() + @"'
                           WHERE `SyncId` = @syncid_d";
                //Console.WriteLine(sSQLcd);
                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
            }

            foreach (cls_giftcheque giftchequenew in giftchequesnew)
            {
                tempStringList = GetListStringAndInsertNextSyncId("collectiondetail");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `collectiondetail` SET
                                `headid` = @collectionheadwid,
                                `method` = 13,
                                `amount` = " + giftchequenew.getamount() + @"
                           WHERE `SyncId` = @syncid_d";

                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
                transactionQueryList.Add("SET @collectiondetailwid = @syncid_d");

                tempStringList = GetListStringAndInsertNextSyncId("posgiftchequepayment");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `posgiftchequepayment` SET
                            `collectiondetailid` = @collectiondetailwid, 
                            `giftchequeno` = '" + giftchequenew.get_referenceno() + @"', 
                            `expdate` = '" + giftchequenew.getexpdate().ToString("yyyy-MM-dd") + @"', 
                            `memo` = '" + escapeString(giftchequenew.get_memo()) + @"', 
                            `amount` = '" + giftchequenew.getamount() + @"'
                           WHERE `SyncId` = @syncid_d";
                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
            }

            foreach (cls_CustomPaymentsInfo custompayment in custompaymentsinfo)
            {
                tempStringList = GetListStringAndInsertNextSyncId("collectiondetail");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `collectiondetail` SET
                                `headid` = @collectionheadwid,
                                `method` = " + custompayment.get_paymentwid() + @", 
                                `amount` = " + custompayment.get_amount() + @"
                           WHERE `SyncId` = @syncid_d";
                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);

                string field1info = custompayment.get_field1info();
                string field2info = custompayment.get_field2info();
                string field3info = custompayment.get_field3info();
                string field4info = custompayment.get_field4info();
                string field5info = custompayment.get_field5info();
                string field6info = custompayment.get_field6info();

                if (field1info.Length > 0 || field2info.Length > 0 || field3info.Length > 0 ||
                    field4info.Length > 0 || field5info.Length > 0 || field6info.Length > 0)
                {
                    sSQLcs = @"INSERT INTO `poscustompayments`
                            (`detailid`,`field1`,`field2`,`field3`,`field4`,`field5`,`field6`)
                            VALUES
                            ( @syncid_d, '" + escapeString(field1info) + @"',
                                '" + escapeString(field2info) + @"','" + escapeString(field3info) + @"',
                                '" + escapeString(field4info) + @"','" + escapeString(field5info) + @"',
                                '" + escapeString(field6info) + @"')";
                    //setdb(sSQLcs);
                    transactionQueryList.Add(sSQLcs);
                }
            }

            if (mem_points != 0)
            {
                tempStringList = GetListStringAndInsertNextSyncId("collectiondetail");
                foreach (string str in tempStringList)
                {
                    transactionQueryList.Add(str);
                }
                sSQLcd = @"UPDATE `collectiondetail` SET
                                `headid` = @collectionheadwid,
                                `method` = 8, 
                                `amount` = " + mem_points + @"
                           WHERE `SyncId` = @syncid_d";

                //setdb(sSQLcd);
                transactionQueryList.Add(sSQLcd);
            }
            tempStringList = update_synctable_liststring("saleshead", salesheadwid.ToString());
            foreach (string str in tempStringList)
            {
                transactionQueryList.Add(str);
            }

            tempStringList = update_synctable_liststring("collectionhead", "@collectionheadwid");
            foreach (string str in tempStringList)
            {
                transactionQueryList.Add(str);
            }

            transactionQueryList.Add("select 'SUCCESS'");

            string returnVal = exec_trans(transactionQueryList, 5);

            if (returnVal != "SUCCESS")
            {
                return(-1);
            }
            return(0);
        }