Exemple #1
0
        private void UpdateCalculation(int paymentMethodIndex)
        {
            try
                {
                Double tempTotalPaid = 0.0;

                Debug.WriteLine("UpdateCalc 1");
                tempTotalPaid += Double.Parse(g_CashLabel.Text.Substring(Program.currency.Length)) + Double.Parse(g_EFTLabel.Text.Substring(Program.currency.Length)) + Double.Parse(g_ChequeLabel.Text.Substring(Program.currency.Length))
                     + Double.Parse(g_AccountLabel.Text.Substring(Program.currency.Length)) + Double.Parse(complementorylabel.Text.Substring(Program.currency.Length));

                Debug.WriteLine("UpdateCalc 2");
                Double tempBillTotal = m_dTotalAmount + Convert.ToDouble("0" + g_ServiceChargeLabel.Text.Substring(Program.currency.Length));
                Debug.WriteLine("UpdateCalc 3");
                Double tempDifference = tempBillTotal - tempTotalPaid;
                Debug.WriteLine("UpdateCalc 4");
                if (tempDifference > 0)
                {
                    m_dBalance = tempDifference;
                    g_BalaceLabel.Text = String.Format("Balance Due {0}" + m_dBalance.ToString("F02"), Program.currency);
                    Debug.WriteLine("UpdateCalc 5");
                }
                else
                {
                    if (CurrentPaymentMethod.Equals("Cash"))
                    {
                        if (m_isAddServiceCharge == false)
                        {
                            g_CashLabel.Text = Program.currency + m_dBalance.ToString("F02");
                        }
                    }
                    else if (CurrentPaymentMethod.Equals("EFT"))
                    {
                        if (m_isAddServiceCharge == false)
                        {
                            g_EFTLabel.Text = Program.currency + m_dBalance.ToString("F02");
                        }
                    }
                    else if (CurrentPaymentMethod.Equals("Due"))
                    {
                        if (m_isAddServiceCharge == false)
                        {
                            g_ChequeLabel.Text = Program.currency + m_dBalance.ToString("F02");
                        }
                    }
                    else if (CurrentPaymentMethod.Equals("Voucher"))
                    {
                        if (m_isAddServiceCharge == false)
                        {
                            g_VoucherLabel.Text = Program.currency + m_dBalance.ToString("F02");
                        }
                    }
                    else if (CurrentPaymentMethod.Equals("Account"))
                    {
                        if (m_isAddServiceCharge == false)
                        {
                            g_AccountLabel.Text = Program.currency + m_dBalance.ToString("F02");
                        }
                    }
                    else if (CurrentPaymentMethod.Equals("Discount"))
                    {
                        g_DiscountLabel.Text = Program.currency + m_dBalance.ToString("F02");
                    }
                    else if (CurrentPaymentMethod.Equals("Deposit"))
                    {
                        g_DepositUsedLabel.Text = Program.currency + m_dBalance.ToString("F02");
                    }

                    else if (CurrentPaymentMethod.Equals("Complementory"))
                    {
                        if (m_isAddServiceCharge == false)
                        {
                            complementorylabel.Text = Program.currency + m_dBalance.ToString("F02");
                        }
                    }

                    Debug.WriteLine("UpdateCalc 6");
                    m_dBalance = -tempDifference;

                    g_BalaceLabel.Text = "Pay Back " + Program.currency + (m_dBalance-tipsamount).ToString("F02");

                    Debug.WriteLine("UpdateCalc 7");
                    CPaymentManager tempPaymentManager = new CPaymentManager();

                    /***********************/
                    /********New Print******/
                    /***********************/

                    if (isCheatManuallyhandled())
                    {
                        DialogResult dresult = MessageBox.Show("Make It Open?", "Message", MessageBoxButtons.YesNo);

                        if (dresult == DialogResult.Yes)
                        {
                            makeOpen = true;
                        }
                        if (dresult == DialogResult.No)
                        {
                            makeOpen = false;
                        }
                    }

                    DataSet tempDataSet = new DataSet();
                    tempDataSet.ReadXml("Config/Print_Config.xml");
                    if (tempDataSet.Tables[0].Rows[0]["PrintPaymentBill"].ToString().ToLower().Equals("true"))
                    {
                        Debug.WriteLine("UpdateCalc 17");
                        PrintPaymentBill(paymentMethodIndex);//Payment method index .Cash=1,EFT=2,Cheque=3
                    }

                    COrderManager temmpOrderManager = new COrderManager();
              COrderDiscount tempOrderDiscount = new COrderDiscount();
              CResult ooResult = temmpOrderManager.OrderDiscountGetByOrderID(m_iOrderID);
                    double itemDiscount = 0;
              if (ooResult.IsSuccess && ooResult.Data != null)
              {

              tempOrderDiscount = (COrderDiscount) ooResult.Data;
              itemDiscount = tempOrderDiscount.TotalItemDiscount;
              }

                    //Check whether payment data exists
                    if (m_cPayment == null)
                    {
                        Debug.WriteLine("UpdateCalc 8");
                        ///insert into payment table
                        CPayment tempPayment = new CPayment();
                        tempPayment.OrderID = m_iOrderID;

                        //get pc id from pc ip
                        CPcInfoManager tempPcInfoManager = new CPcInfoManager();
                        IPHostEntry ipEntry = System.Net.Dns.GetHostByName(Dns.GetHostName());

                        CPcInfo tempPcInfo = (CPcInfo)tempPcInfoManager.PcInfoByPcIP(ipEntry.AddressList[0].ToString()).Data;

                        tempPayment.PcID = tempPcInfo.PcID;
                        Debug.WriteLine("UpdateCalc 9");
                        tempPayment.TotalAmount = m_dTotalAmount;
                        tempPayment.CashAmount = Double.Parse(g_CashLabel.Text.Substring(Program.currency.Length));
                        tempPayment.EFTAmount = Double.Parse(g_EFTLabel.Text.Substring(Program.currency.Length));
                        tempPayment.ChequeAmount = Double.Parse(g_ChequeLabel.Text.Substring(Program.currency.Length));
                        tempPayment.ServiceAmount = m_serviceCharge_cash + m_serviceCharge_voucher + m_serviceCharge_eft + m_serviceCharge_cheque + m_serviceCharge_accounts - tipsamount;  //Double.Parse(g_ServiceChargeLabel.Text.Substring(Program.currency.Length));
                        tempPayment.VoucherAmount = Double.Parse(complementorylabel.Text.Substring(Program.currency.Length));
                        tempPayment.Discount = Double.Parse(g_DiscountLabel.Text.Substring(Program.currency.Length));
                        tempPayment.AccountPay = Double.Parse(g_AccountLabel.Text.Substring(Program.currency.Length));
                        tempPayment.DepositID = m_oDeposit.DepositID;
                        tempPayment.DepositAmount = Double.Parse(g_DepositUsedLabel.Text.Substring(Program.currency.Length));
                        tempPayment.PaymentTime = System.DateTime.Now;

                        tempPayment.ServiceChargeCash = m_serviceCharge_cash;
                        tempPayment.ServiceChargeCheque = m_serviceCharge_cheque;
                        tempPayment.ServiceChargeEft = m_serviceCharge_eft;
                        tempPayment.ServiceChargeVoucher = m_serviceCharge_voucher;
                        tempPayment.ServiceChargeAcc = m_serviceCharge_accounts;

                        tempPayment.DueMessage = dueMessage;
                        tempPayment.ComplementoryMessage = complementoryMessage;

                        double totalCost = GetTotalCost(m_iOrderID);
                        tempPayment.TotalCost = totalCost;
                        tempPayment.TipsAmount = tipsamount;

                        tempPayment.VatImposed = Program.vat.ToString();

                        tempPayment.membershipDiscount = (double)membershipdiscount;
                        tempPayment.ItemDiscount = itemDiscount;

                        //tempPayment.VatImposed = Program.vat.ToString();
                        tempPayment.GuestBill = gusetBillStr;
                        COrderWaiterDao orderWaiterDao = new COrderWaiterDao(); // Change by Mithu
                        COrderwaiter orderWaiter = orderWaiterDao.GetOrderwaiterByOrderID(m_iOrderID); // Change by Mithu

                        try
                        {
                            tempPayment.Waiter = orderWaiter.WaiterName;
                        }
                        catch (Exception)
                        {

                        }

                        if (makeOpen)
                            tempPayment.Vat_stat = true;
                        else
                            tempPayment.Vat_stat = false;

                        tempPayment.PaymentPerson = RMSGlobal.LoginUserName;

                        DataSet tempStockDataSet = new DataSet();
                        tempStockDataSet.ReadXml("Config/StockSetting.xml");
                        bool isAllowedToOrder = Convert.ToBoolean(tempStockDataSet.Tables[0].Rows[0]["AllowedtoOrder"].ToString());
                        if (!isAllowedToOrder)
                        {
                            COrderDetailsDAO aDao = new COrderDetailsDAO();
                            List<COrderDetails> aList = new List<COrderDetails>();
                            double cost = 0.0;
                            try
                            {
                                aList = aDao.OrderDetailsGetAll();
                                var check = from list in aList where list.OrderID == tempPayment.OrderID select list;
                                SaleReportDAO aSaleReportDao = new SaleReportDAO();
                                aSaleReportDao.InsertOrUpdateSaleRawmaterialsReport(check);
                            }
                            catch
                            {
                            }

                        }

                        CResult oResult = tempPaymentManager.InsertPayment(tempPayment);
                        if (oResult.IsSuccess && oResult.Data != null)
                        {
                            tempPayment = (CPayment)oResult.Data;
                            m_cPayment = tempPayment;
                            Debug.WriteLine("UpdateCalc 10");
                        }
                    }
                    else
                    {
                        Debug.WriteLine("UpdateCalc 11");
                        //update payment table
                        CPayment tempPayment = new CPayment();
                        tempPayment.PaymentID = m_cPayment.PaymentID;
                        tempPayment.OrderID = m_iOrderID;

                        tempPayment.TotalAmount = m_dTotalAmount;
                        tempPayment.CashAmount = Double.Parse(g_CashLabel.Text.Substring(Program.currency.Length));
                        tempPayment.EFTAmount = Double.Parse(g_EFTLabel.Text.Substring(Program.currency.Length));
                        tempPayment.ChequeAmount = Double.Parse(g_ChequeLabel.Text.Substring(Program.currency.Length));
                        tempPayment.ServiceAmount = m_serviceCharge_cash + m_serviceCharge_voucher + m_serviceCharge_eft + m_serviceCharge_cheque + m_serviceCharge_accounts - tipsamount;  //Double.Parse(g_ServiceChargeLabel.Text.Substring(Program.currency.Length));
                        tempPayment.VoucherAmount = Double.Parse(complementorylabel.Text.Substring(Program.currency.Length));
                        tempPayment.Discount = Double.Parse(g_DiscountLabel.Text.Substring(Program.currency.Length));
                        tempPayment.AccountPay = Double.Parse(g_AccountLabel.Text.Substring(Program.currency.Length));
                        tempPayment.DepositID = m_oDeposit.DepositID;
                        tempPayment.DepositAmount = Double.Parse(g_DepositUsedLabel.Text.Substring(Program.currency.Length));
                        tempPayment.PaymentTime = System.DateTime.Now;

                        tempPayment.ServiceChargeCash = m_serviceCharge_cash;
                        tempPayment.ServiceChargeCheque = m_serviceCharge_cheque;
                        tempPayment.ServiceChargeEft = m_serviceCharge_eft;
                        tempPayment.ServiceChargeVoucher = m_serviceCharge_voucher;
                        tempPayment.ServiceChargeAcc = m_serviceCharge_accounts;
                        tempPayment.VatImposed = Program.vat.ToString();
                        tempPayment.TipsAmount = tipsamount;
                        tempPayment.GuestBill = gusetBillStr;
                        tempPayment.membershipDiscount = (double)membershipdiscount;
                        tempPayment.ItemDiscount = itemDiscount;
                        //tempPayment.DueMessage = dueMessage;
                        //tempPayment.ComplementoryMessage = complementoryMessage;

                        if (isCheatManuallyhandled())
                        {
                            DialogResult dresult = MessageBox.Show("Make It Open?", "Message", MessageBoxButtons.YesNo);

                            if (dresult == DialogResult.Yes)
                            {
                                makeOpen = true;
                            }
                            if (dresult == DialogResult.No)
                            {
                                makeOpen = false;
                            }
                        }

                        if (makeOpen)
                            tempPayment.Vat_stat = true;
                        else
                            tempPayment.Vat_stat = false;
                        tempPayment.PaymentPerson = RMSGlobal.LoginUserName;

                        tempPaymentManager.UpdatePayment(tempPayment);
                        m_cPayment = tempPayment;
                        Debug.WriteLine("UpdateCalc 12");
                    }

                    //Update Deposit
                    CDepositManager tempDepositManager = new CDepositManager();
                    tempDepositManager.UpdateDeposit(m_oDeposit);

                    //opening cash drawer
                    try
                    {
                        CPrintMethods tempPrintMethods = new CPrintMethods();
                        tempPrintMethods.OpenDrawer();

                        #region "Tracking Area"
                        CCommonConstants m_oCommonConstants;
                        //Drawer Opening log
                        DateTime dtPayment = DateTime.Now;
                        dtPayment = new DateTime(dtPayment.Year, dtPayment.Month, dtPayment.Day, dtPayment.Hour, dtPayment.Minute, dtPayment.Second);
                        Int64 dateTime = dtPayment.Ticks;
                        m_oCommonConstants = ConfigManager.GetConfig<CCommonConstants>();
                        CUserInfo objUserInfo = m_oCommonConstants.UserInfo;
                        tempPaymentManager.SaveDrawerLogs(RMSGlobal.Terminal_Id, objUserInfo.UserName, dateTime);
                        #endregion

                        Debug.WriteLine("UpdateCalc 18");
                    }
                    catch (Exception eee)
                    {
                        Debug.WriteLine("UpdateCalc 19");
                        Debug.WriteLine(eee.ToString());
                    }

                    ///Print Payment Bill
                    ///
                    /*  DataSet tempDataSet = new DataSet();
                      tempDataSet.ReadXml("Config/Print_Config.xml");
                      if (tempDataSet.Tables[0].Rows[0]["PrintPaymentBill"].ToString().ToLower().Equals("true"))
                      {
                          Debug.WriteLine("UpdateCalc 17");
                          PrintPaymentBill(paymentMethodIndex);//Payment method index .Cash=1,EFT=2,Cheque=3
                      }
              */

                    COrderManager tempOrderManager = new COrderManager();
                    COrderInfo tempOrderInfo = null;

                    if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) //If local orders are processed
                    {
                        tempOrderInfo = (COrderInfo)tempOrderManager.OrderInfoByOrderID(m_iOrderID).Data;
                        tempOrderManager.UpdateOrderInfo(tempOrderInfo);
                        Debug.WriteLine("UpdateCalc 13");
                        tempOrderManager.InsertOrderArchive(tempOrderInfo);
                        Debug.WriteLine("UpdateCalc 14");
                        tempOrderManager.InsertOrderDetailsArchive(tempOrderInfo);
                        Debug.WriteLine("UpdateCalc 15");
                    }
                    else //If online orders are processed
                    {
                        tempOrderInfo = (COrderInfo)tempOrderManager.OrderInfoByOrderID(m_iOrderID).Data;
                        tempOrderManager.InsertOnlineOrderArchive(tempOrderInfo);
                        Debug.WriteLine("Online orders archiving");
                    }

                    tempOrderManager.DeleteTableInfo(tempOrderInfo.TableNumber, m_sTableType);
                    Debug.WriteLine("UpdateCalc 16");

                    //insert voucher
                    tempOrderManager.InsertOrderVoucher(m_oOrderVoucher);

                    ///back to main screen
                    ///

                    CFormManager.Forms.Pop();
                    Form tempForm = CFormManager.Forms.Pop();
                    tempForm.Show();
                    this.Close();
                }
                g_BalaceLabel.ForeColor = Color.Red;
            }
            catch (Exception eee)
            {
                //MessageBox.Show(eee.ToString());
                Debug.WriteLine("UpdateCalc catch");
                Debug.WriteLine(eee.ToString());
            }
        }
Exemple #2
0
        //private void btnPLU_Click(object sender, EventArgs e)
        //{
        //    int priceTakeType;
        //    Int32 productPLU = 0;
        //    int returnVal = 0;
        //    Int32 productQuantity = 0;
        //    COrderManager objOrderManager = new COrderManager();
        //    if (m_iType == m_cCommonConstants.TableType)
        //    {
        //        priceTakeType = 1;
        //    }
        //    else if (m_iType == m_cCommonConstants.TakeAwayType)
        //    {
        //        priceTakeType = 2;
        //    }
        //    else
        //    {
        //        priceTakeType = 3;
        //    }
        //    CCalculatorForm tableNumberForm = new CCalculatorForm("Product PLU Information", "PLU of the Product");
        //    tableNumberForm.ShowDialog();
        //    if (CCalculatorForm.inputResult.Equals("Cancel"))
        //        return;
        //    if (CCalculatorForm.inputResult.Equals("") || Int32.Parse(CCalculatorForm.inputResult) == 0)
        //    {
        //        CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!");
        //        tempMessageBox.ShowDialog();
        //        return;
        //    }
        //    productPLU = Convert.ToInt32("0" + CCalculatorForm.inputResult);
        //    CResult objProductName = objOrderManager.GetProductByProductPLU(productPLU);
        //    if (Convert.ToString(objProductName.Data) == "NO")
        //    {
        //        CMessageBox tempMessageBox = new CMessageBox("Error", "Invalid PLU.Please enter valid PLU");
        //        tempMessageBox.ShowDialog();
        //        return;
        //    }
        //    ProductQuantityForm quantityForm = new ProductQuantityForm(Convert.ToString(objProductName.Data));
        //    quantityForm.ShowDialog();
        //    if (ProductQuantityForm.m_productQuantity.Equals("Cancel"))
        //    {
        //        return;
        //    }
        //    if (ProductQuantityForm.m_productQuantity.Equals("") || Int32.Parse(ProductQuantityForm.m_productQuantity) == 0)
        //    {
        //        CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!");
        //        tempMessageBox.ShowDialog();
        //        return;
        //    }
        //    productQuantity = Convert.ToInt32("0" + ProductQuantityForm.m_productQuantity);
        //    CResult oResult = objOrderManager.GetPluDataByProductPLU(productPLU, priceTakeType, orderID, productQuantity);
        //    if (oResult.IsSuccess && oResult.Data != null)
        //    {
        //        returnVal = int.Parse(oResult.Data.ToString());
        //        //for vat includr option
        //        String queryStr = SqlQueries.GetQuery(Query.LastPLUOrderDetails);
        //        CDalConfig oTempDal = ConfigManager.GetConfig<CDalConfig>();
        //        String tempConnStr = oTempDal.ConnectionString;
        //        // Create a new data adapter based on the specified query.
        //        SqlDataAdapter dataAdapter = new SqlDataAdapter(queryStr, tempConnStr);
        //        // Populate a new data table and bind it to the BindingSource.
        //        DataTable table = new DataTable();
        //        //table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        //        dataAdapter.Fill(table);
        //        int CategoryID = Convert.ToInt32(table.Rows[0]["product_id"].ToString());
        //        Double amount = Convert.ToDouble(table.Rows[0]["amount"].ToString());
        //        int catLavel=Convert.ToInt32(table.Rows[0]["cat_level"].ToString());
        //        //vat in cat Three
        //        double vatRate = 0;
        //        bool vat_included = false;
        //        double vatAmountRate = 0;
        //        if(catLavel==3)
        //        {
        //        DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + CategoryID.ToString());
        //        vatRate = 0;
        //        vat_included = false;
        //        vatAmountRate = 0;
        //        try
        //        {
        //            vatRate = Convert.ToDouble(temp2DataRowArray[0]["vat_Rate"].ToString());
        //            vat_included = Convert.ToBoolean(temp2DataRowArray[0]["vat_included"].ToString());
        //            if (vat_included)
        //            {
        //                vatAmountRate = (amount * vatRate) / 100;
        //                // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString();
        //                // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString();
        //            }
        //            else
        //            {
        //                vatAmountRate = 0.00;
        //            }
        //        }
        //        catch (Exception ex) { }
        //        }
        //        if(catLavel==4)
        //        {
        //            DataRow[] temp3DataRowArray = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + CategoryID);
        //        vatRate = 0;
        //        vat_included = false;
        //        vatAmountRate = 0;
        //        try
        //        {
        //            vatRate = Convert.ToDouble(temp3DataRowArray[0]["vat_Rate"].ToString());
        //            vat_included = Convert.ToBoolean(temp3DataRowArray[0]["vat_included"].ToString());
        //            if (vat_included)
        //            {
        //                vatAmountRate = (amount * vatRate) / 100;
        //                // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString();
        //                // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString();
        //            }
        //            else
        //            {
        //                vatAmountRate = 0.00;
        //            }
        //        }
        //        catch (Exception ex) { }
        //        }
        //        //string tableTypePrice = string.Empty;
        //        //if (m_iType == m_cCommonConstants.TableType)
        //        //{
        //        //    tableTypePrice = temp2DataRowArray[0]["table_price"].ToString();
        //        //}
        //        //else if (m_iType == m_cCommonConstants.TakeAwayType)
        //        //{
        //        //    tableTypePrice = temp2DataRowArray[0]["tw_price"].ToString();
        //        //}
        //        COrderManager tempOrderManager = new COrderManager();
        //        COrderDetails tempOrderDetails = new COrderDetails();
        //        if (returnVal == 1)
        //        {
        //            //update Order_details table
        //            //int tempRowIndex = tempResult;
        //            //int qty = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty;
        //            //tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty;
        //            //tempDataGridView.Rows[tempRowIndex].Cells[2].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02");
        //            tempOrderDetails.OrderDetailsID = Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString());
        //            tempOrderDetails.OrderID =Convert.ToInt32(table.Rows[0]["order_id"].ToString());
        //            tempOrderDetails.ProductID =Convert.ToInt32( table.Rows[0]["product_id"].ToString());
        //            tempOrderDetails.CategoryLevel = Convert.ToInt32(table.Rows[0]["cat_level"].ToString());
        //            tempOrderDetails.UnitPrice = 0.00;
        //            tempOrderDetails.OrderQuantity = Convert.ToInt32(table.Rows[0]["quantity"].ToString());
        //            tempOrderDetails.OrderAmount = Convert.ToDouble(table.Rows[0]["amount"].ToString());
        //            tempOrderDetails.OrderFoodType = table.Rows[0]["food_type"].ToString();
        //           // tempOrderDetails.OnlineItemSequenceNumber = Convert.ToInt64("0" + tempDataGridView.Rows[tempRowIndex].Cells[5].Value.ToString());
        //           // tempOrderDetails.PrintedQuantity = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[7].Value.ToString());
        //            if (vat_included)
        //            {
        //                tempOrderDetails.VatTotal = vatAmountRate;
        //            }
        //            else
        //            {
        //                tempOrderDetails.VatTotal = 0.00;
        //            }
        //            //if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper())
        //            //{
        //            //    tempOrderManager.UpdateOrderDetails(tempOrderDetails);
        //            //}
        //            //else
        //            //{
        //            //    tempOrderManager.UpdateOnlineOrderDetails(tempOrderDetails);
        //            //}
        //            try
        //            {
        //                tempOrderManager.UpdateOrderDetails(tempOrderDetails);
        //            }
        //            catch { }
        //        }
        //        //tempOrderDetails.VatTotal = vatAmountRate;
        //        //tempOrderDetails.OrderDetailsID =Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString());
        //        //try
        //        //{
        //        //tempOrderManager.UpdateOrderDetails(tempOrderDetails);
        //        //}
        //        //catch { }
        //    }
        //    if (returnVal == 0)
        //    {
        //        MessageBox.Show("Please enter valid plu product", RMSGlobal.MessageBoxTitle,
        //            MessageBoxButtons.OK, MessageBoxIcon.Information);
        //    }
        //    else
        //    {
        //        COrderDetailsDAO orderDetailsDao = new COrderDetailsDAO();
        //        orderDetailsDao.UpdateOrderDetailsPricebyPLUProductTablePrice(productPLU, orderID, priceTakeType);
        //    }
        //    this.LoadOrderDetails();
        //    btnPLU_Click(sender, e);
        //}
        private void btnPLU_Click(object sender, EventArgs e)
        {
            int priceTakeType;
            Int32 productPLU = 0;
            int returnVal = 0;
            Int32 productQuantity = 0;
            COrderManager objOrderManager = new COrderManager();

            if (m_iType == m_cCommonConstants.TableType)
            {
                priceTakeType = 1;
            }
            else if (m_iType == m_cCommonConstants.TakeAwayType)
            {
                priceTakeType = 2;
            }
            else
            {
                priceTakeType = 3;
            }

            CCalculatorForm tableNumberForm = new CCalculatorForm("Product PLU Information", "PLU of the Product");
            tableNumberForm.ShowDialog();

            if (CCalculatorForm.inputResult.Equals("Cancel"))
                return;

            if (CCalculatorForm.inputResult.Equals("") || Int32.Parse(CCalculatorForm.inputResult) == 0)
            {
                CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!");
                tempMessageBox.ShowDialog();
                return;
            }

            productPLU = Convert.ToInt32("0" + CCalculatorForm.inputResult);

            // Add for find updating order_detail
            int id = productPLU;
            long order = orderID;
            COrderDetailsDAO aDao = new COrderDetailsDAO();
            List<COrderDetails> aList = aDao.OrderDetailsGetAll();

            //  CResult objProductName = objOrderManager.GetProductByProductPLU(productPLU, priceTakeType);
            CResult objProductName = objOrderManager.GetProductByProductPLU(productPLU);

            var check = (from orderdetail in aList
                         where (orderdetail.OrderID == orderID && orderdetail.ProductID == objProductName.Productid)
                         select orderdetail);

            if (Convert.ToString(objProductName.Data) == "NO")
            {
                CMessageBox tempMessageBox = new CMessageBox("Error", "Invalid PLU.Please enter valid PLU");
                tempMessageBox.ShowDialog();
                return;
            }

            ProductQuantityForm quantityForm = new ProductQuantityForm(Convert.ToString(objProductName.Data));
            quantityForm.ShowDialog();

            if (ProductQuantityForm.m_productQuantity.Equals("Cancel"))
            {
                return;
            }
            if (ProductQuantityForm.m_productQuantity.Equals("") || Int32.Parse(ProductQuantityForm.m_productQuantity) == 0)
            {
                CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!");
                tempMessageBox.ShowDialog();
                return;
            }

            productQuantity = Convert.ToInt32("0" + ProductQuantityForm.m_productQuantity);

            // Add for updating order_detail when orderwith same product
            if (check.Count() == 1)
            {

                COrderDetails aOrderDetails = new COrderDetails();
                aOrderDetails = check.Single();
                //double vat = aOrderDetails.Amount_with_vat - aOrderDetails.OrderAmount;
                //vat = (vat * 100) / aOrderDetails.OrderAmount;
                productQuantity += aOrderDetails.OrderQuantity;
                aOrderDetails.OrderQuantity = productQuantity;
                aOrderDetails.OrderAmount = aOrderDetails.UnitPrice * productQuantity;
                aOrderDetails.PrintedQuantity = aOrderDetails.PrintedQuantity;
                aOrderDetails.VatTotal = (objProductName.VateRate * aOrderDetails.OrderAmount) / 100.0;
                aOrderDetails.Amount_with_vat = aOrderDetails.OrderAmount + aOrderDetails.VatTotal;

                COrderDetailsDAO aCOrderDetailsDao = new COrderDetailsDAO();
                aCOrderDetailsDao.OrderDetailsUpdate(aOrderDetails);

                //COrderDetailsDAO orderDetailsDao = new COrderDetailsDAO();
                //orderDetailsDao.UpdateOrderDetailsPricebyPLUProductTablePrice(productPLU, orderID, priceTakeType);

            }

            if (check.Count() == 0)
            {
                CResult oResult = objOrderManager.GetPluDataByProductPLU(productPLU, priceTakeType, orderID,
                                                                         productQuantity);

                if (oResult.IsSuccess && oResult.Data != null)
                {
                    returnVal = int.Parse(oResult.Data.ToString());

                    //for vat includr option

                    String queryStr = SqlQueries.GetQuery(Query.LastPLUOrderDetails);
                    CDalConfig oTempDal = ConfigManager.GetConfig<CDalConfig>();
                    String tempConnStr = oTempDal.ConnectionString;
                    // Create a new data adapter based on the specified query.
                    SqlDataAdapter dataAdapter = new SqlDataAdapter(queryStr, tempConnStr);
                    // Populate a new data table and bind it to the BindingSource.
                    DataTable table = new DataTable();
                    //table.Locale = System.Globalization.CultureInfo.InvariantCulture;
                    dataAdapter.Fill(table);

                    int CategoryID = Convert.ToInt32(table.Rows[0]["product_id"].ToString());
                    Double amount = Convert.ToDouble(table.Rows[0]["amount"].ToString());

                    int catLavel = Convert.ToInt32(table.Rows[0]["cat_level"].ToString());
                    //vat in cat Three

                    double vatRate = 0;
                    bool vat_included = false;
                    double vatAmountRate = 0;
                    if (catLavel == 3)
                    {
                        DataRow[] temp2DataRowArray =
                            Program.initDataSet.Tables["Category3"].Select("cat3_id = " + CategoryID.ToString());

                        vatRate = 0;
                        vat_included = false;
                        vatAmountRate = 0;
                        try
                        {
                            vatRate = Convert.ToDouble(temp2DataRowArray[0]["vat_Rate"].ToString());
                            vat_included = Convert.ToBoolean(temp2DataRowArray[0]["vat_included"].ToString());

                            if (vat_included)
                            {
                                vatAmountRate = (amount * vatRate) / 100;

                                // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString();
                                // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString();
                            }
                            else
                            {
                                vatAmountRate = 0.00;
                            }

                        }
                        catch (Exception ex)
                        {
                        }

                    }

                    if (catLavel == 4)
                    {
                        DataRow[] temp3DataRowArray =
                            Program.initDataSet.Tables["Category4"].Select("cat4_id = " + CategoryID);

                        vatRate = 0;
                        vat_included = false;
                        vatAmountRate = 0;
                        try
                        {
                            vatRate = Convert.ToDouble(temp3DataRowArray[0]["vat_Rate"].ToString());
                            vat_included = Convert.ToBoolean(temp3DataRowArray[0]["vat_included"].ToString());

                            if (vat_included)
                            {
                                vatAmountRate = (amount * vatRate) / 100;

                                // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString();
                                // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString();
                            }
                            else
                            {
                                vatAmountRate = 0.00;
                            }

                        }
                        catch (Exception ex)
                        {
                        }

                    }

                    //string tableTypePrice = string.Empty;
                    //if (m_iType == m_cCommonConstants.TableType)
                    //{
                    //    tableTypePrice = temp2DataRowArray[0]["table_price"].ToString();
                    //}
                    //else if (m_iType == m_cCommonConstants.TakeAwayType)
                    //{
                    //    tableTypePrice = temp2DataRowArray[0]["tw_price"].ToString();
                    //}

                    COrderManager tempOrderManager = new COrderManager();
                    COrderDetails tempOrderDetails = new COrderDetails();

                    if (returnVal == 1)
                    {
                        //update Order_details table
                        //int tempRowIndex = tempResult;
                        //int qty = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty;
                        //tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty;
                        //tempDataGridView.Rows[tempRowIndex].Cells[2].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02");
                        tempOrderDetails.OrderDetailsID = Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString());
                        tempOrderDetails.OrderID = Convert.ToInt32(table.Rows[0]["order_id"].ToString());
                        tempOrderDetails.ProductID = Convert.ToInt32(table.Rows[0]["product_id"].ToString());
                        tempOrderDetails.CategoryLevel = Convert.ToInt32(table.Rows[0]["cat_level"].ToString());
                        tempOrderDetails.UnitPrice = 0.00;
                        tempOrderDetails.OrderQuantity = Convert.ToInt32(table.Rows[0]["quantity"].ToString());
                        tempOrderDetails.OrderAmount = Convert.ToDouble(table.Rows[0]["amount"].ToString());
                        tempOrderDetails.OrderFoodType = table.Rows[0]["food_type"].ToString();
                        // tempOrderDetails.OnlineItemSequenceNumber = Convert.ToInt64("0" + tempDataGridView.Rows[tempRowIndex].Cells[5].Value.ToString());
                        // tempOrderDetails.PrintedQuantity = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[7].Value.ToString());
                        if (vat_included)
                        {
                            tempOrderDetails.VatTotal = vatAmountRate;
                        }
                        else
                        {
                            tempOrderDetails.VatTotal = 0.00;
                        }

                        //if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper())
                        //{
                        //    tempOrderManager.UpdateOrderDetails(tempOrderDetails);
                        //}
                        //else
                        //{
                        //    tempOrderManager.UpdateOnlineOrderDetails(tempOrderDetails);
                        //}

                        try
                        {
                            tempOrderDetails.Amount_with_vat = tempOrderDetails.OrderAmount + tempOrderDetails.VatTotal;
                            tempOrderManager.UpdateOrderDetails(tempOrderDetails);
                        }
                        catch
                        {
                        }
                    }

                    //tempOrderDetails.VatTotal = vatAmountRate;
                    //tempOrderDetails.OrderDetailsID =Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString());
                    //try
                    //{
                    //tempOrderManager.UpdateOrderDetails(tempOrderDetails);
                    //}
                    //catch { }

                }

                if (returnVal == 0)
                {
                    MessageBox.Show("Please enter valid plu product", RMSGlobal.MessageBoxTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    COrderDetailsDAO orderDetailsDao = new COrderDetailsDAO();
                    orderDetailsDao.UpdateOrderDetailsPricebyPLUProductTablePrice(productPLU, orderID, priceTakeType);

                }
            }

            this.LoadOrderDetails();

            btnPLU_Click(sender, e);
        }
Exemple #3
0
        //Add for vat and cost find out
        private COrderDetails GetAll(COrderDetails objDetails)
        {
            try
            {
                COrderDetailsDAO aDao = new COrderDetailsDAO();
                List<COrderDetails> aCOrderDetailses = aDao.OrderDetailsGetAll();
                COrderDetails orderDetails = new COrderDetails();
                foreach (COrderDetails details in aCOrderDetailses)
                {
                    if (details.OrderID == objDetails.OrderID && details.ProductID == objDetails.ProductID)
                    {
                        orderDetails = details;
                    }
                }

                int quantity = objDetails.OrderQuantity;
                double unit_amount = (orderDetails.OrderAmount / orderDetails.OrderQuantity);
                double unit_vat = ((orderDetails.Amount_with_vat - orderDetails.OrderAmount) * 100) / orderDetails.OrderAmount;
                unit_vat = (unit_amount * unit_vat) / 100.0;
                objDetails.OrderAmount = (unit_amount * quantity);
                objDetails.VatTotal = unit_vat * quantity;
                objDetails.Amount_with_vat = objDetails.OrderAmount + objDetails.VatTotal;
                objDetails.KitchenQuantity = orderDetails.KitchenQuantity;

            }
            catch
            {

            }
            return objDetails;
        }