private void Close_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ProgressB.Maximum = 10;
         Recalculate.ReCalculate_Cost_Qty(DTCurrentMonth.Rows[0], DTPreviousMonth);
         ProgressB.Value = 50;
         ProgressB.UpdateLayout();
         Recalculate.CloseMonth(DTCurrentMonth.Rows[0]);
         ProgressB.Value = 90;
         where           = "Month = '" + Month + "' and Year = '" + Year + "'";
         Classes.UpdateCell("isClosed", "1", where, "Setup_Fiscal_Period");
         ProgressB.Value = 100;
         LoadMonths();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 private void Open_Click(object sender, RoutedEventArgs e)
 {
     where = "Month = '" + PMonth + "' and Year = '" + PYear + "'";
     Classes.UpdateCell("isClosed", "0", where, "Setup_Fiscal_Period");
     LoadMonths();
 }
Example #3
0
        private static void CalculateCost(DataRow DRCurrentMonth, DataTable DTPreviousMonth)
        {
            LoadITEM_COST(DTPreviousMonth);
            where = "_DATE between '" + Convert.ToDateTime(DRCurrentMonth["From"].ToString()).ToString(Classes.sysDateTimeFormat) + "' AND '" + Convert.ToDateTime(DRCurrentMonth["To"].ToString()).ToString(Classes.sysDateTimeFormat) + "'";
            string order = " order by Item_ID, _DATE ";

            DataTable Transactions = Classes.RetrieveData("*", where + order, "TransActions");

            for (int i = 0; i < Transactions.Rows.Count; i++)
            {
                string itemCostKey    = Transactions.Rows[i]["KitchenName"].ToString() + Transactions.Rows[i]["Item_ID"].ToString();
                string ChangedTranKye = Transactions.Rows[i]["ID"].ToString() + Transactions.Rows[i]["Item_ID"].ToString();

                where  = "Trantype = '" + Transactions.Rows[i]["Trantype"].ToString();
                where += "' AND Item_ID = '" + Transactions.Rows[i]["Item_ID"].ToString();
                where += "' AND ID = '" + Transactions.Rows[i]["ID"].ToString() + "'";

                if (Transactions.Rows[i]["Trantype"].ToString() == "Receive" || Transactions.Rows[i]["Trantype"].ToString() == "Transfer_In")
                {
                    if (changed_trasfers.ContainsKey(ChangedTranKye) == true && Transactions.Rows[i]["Trantype"].ToString() == "Transfer_In")
                    {
                        Cost = double.Parse(changed_trasfers[ChangedTranKye]);
                    }
                    else
                    {
                        Cost = double.Parse(Transactions.Rows[i]["Cost"].ToString());
                    }

                    if (Transactions.Rows[i]["Current_Qty"].Equals(Transactions.Rows[i]["Qty"]))
                    {
                        item_cost[itemCostKey] = Cost.ToString();
                        Classes.UpdateCell("CurrentCost", Cost.ToString(), where, "TransActions");
                    }
                    else
                    {
                        double CurrentCost;
                        double CurrentQty = double.Parse(Transactions.Rows[i]["Current_Qty"].ToString()) - double.Parse(Transactions.Rows[i]["Qty"].ToString());
                        if (CurrentQty < 0)
                        {
                            MessageBox.Show("Time error in" + Transactions.Rows[i]["Trantype"] + " " + Transactions.Rows[i]["ID"]);
                            return;
                        }
                        Qty = double.Parse(Transactions.Rows[i]["Qty"].ToString());
                        if (item_cost.ContainsKey(itemCostKey))
                        {
                            CurrentCost = double.Parse(item_cost[itemCostKey]);
                        }
                        else
                        {
                            CurrentCost = double.Parse(Transactions.Rows[i]["Cost"].ToString());
                        }

                        double Current_Qty = double.Parse(Transactions.Rows[i]["Current_Qty"].ToString());
                        string NewCost;

                        if (Current_Qty == 0)
                        {
                            NewCost = "0";
                        }
                        else
                        {
                            NewCost = ((CurrentCost * CurrentQty + Cost * Qty) / Current_Qty).ToString();
                        }

                        item_cost[itemCostKey] = NewCost;
                        Classes.UpdateCell("CurrentCost", NewCost.ToString(), where, "TransActions");
                    }
                }
                else if (Transactions.Rows[i]["Trantype"].ToString() == "Adjactment")
                {
                    item_cost[itemCostKey] = Transactions.Rows[i]["Cost"].ToString();
                    Classes.UpdateCell("CurrentCost", Transactions.Rows[i]["Cost"].ToString(), where, "TransActions");
                }
                else if (Transactions.Rows[i]["Trantype"].ToString() == "Transfer_Out")
                {
                    if (item_cost.ContainsKey(itemCostKey))
                    {
                        if (!item_cost[itemCostKey].Equals(Transactions.Rows[i]["Cost"].ToString()))
                        {
                            changed_trasfers[ChangedTranKye] = item_cost[itemCostKey];
                            Classes.UpdateRow("CurrentCost,Cost", item_cost[itemCostKey] + "," + item_cost[itemCostKey], where, "TransActions");

                            //where = "Item_ID = '" + Transactions.Rows[i]["Item_ID"].ToString() + "' AND Transfer_ID = '" + Transactions.Rows[i]["ID"].ToString() + "'";
                            //Classes.UpdateCell("Cost", item_cost[itemCostKey], where, "Transfer_Kitchens_Items");

                            string tempwhere = "Item_ID = '" + Transactions.Rows[i]["Item_ID"].ToString() + "' AND Request_ID = '" + Transactions.Rows[i]["ID"].ToString() + "'";
                            Classes.UpdateCell("Cost", item_cost[itemCostKey], tempwhere, "Requests_Items");
                            Classes.UpdateCell("Net_Cost", "Cost * Qty", "Requests_Items");

                            DataTable drRoSerial = Classes.RetrieveData("SELECT RO_Serial from RO where Transactions_No = '" + Transactions.Rows[i]["ID"].ToString() + "' and Type = 'Transfer_Kitchen'");
                            if (drRoSerial.Rows.Count > 0)
                            {
                                tempwhere = "Item_ID = '" + Transactions.Rows[i]["Item_ID"].ToString() + "' AND RO_No = '" + drRoSerial.Rows[0][0].ToString() + "'";
                                Classes.UpdateRow("Price_With_Tax,Price_Without_Tax", item_cost[itemCostKey] + "," + item_cost[itemCostKey], tempwhere, "RO_Items");
                                Classes.UpdateCell("Net_Price", "Price_With_Tax * Qty", "RO_Items");
                            }
                        }
                    }
                }
                else if (Transactions.Rows[i]["Trantype"].ToString() == "Generate")
                {
                    Classes.UpdateRow("CurrentCost,Cost", item_cost[itemCostKey] + "," + item_cost[itemCostKey], where, "TransActions");
                    tempwhere = "Item_ID = '" + Transactions.Rows[i]["Item_ID"].ToString() + "' AND Generate_ID = '" + Transactions.Rows[i]["ID"].ToString() + "'";
                    Classes.UpdateCell("Cost", item_cost[itemCostKey], tempwhere, "GenerateRecipe_Items");
                    Classes.UpdateCell("Net_Cost", "Cost * ItemQty", "GenerateRecipe_Items");
                }
            }
        }