private void DeclareIncomplete()
        {
            String sql         = "";
            String picklist_id = txtPicklist.Text;
            String now         = DateTime.Now.ToString();

            // Flags if user chooses missing / bad stocks for order resolution updating
            Boolean has_missing    = false;
            Boolean has_bad_stocks = false;


            DataTable BadStockDT = new DataTable();

            BadStockDT.Columns.Add("Location");
            BadStockDT.Columns.Add("Product");
            BadStockDT.Columns.Add("Uom");
            BadStockDT.Columns.Add("Lot No");
            BadStockDT.Columns.Add("Expiry");
            BadStockDT.Columns.Add("Qty");
            BadStockDT.Columns.Add("Reason");
            BadStockDT.Columns.Add("Bad Stock Storage");


            // Update Picklist
            sql += "UPDATE Picklists SET status = 'DECLARED INCOMPLETE' WHERE picklist_id= '" + picklist_id + "'; ";


            DataTable order_ids = FAQ.GetOrdersFromPicklist(picklist_id);

            // Update Order Status
            foreach (DataRow row in order_ids.Rows)
            {
                sql += " UPDATE ReleaseOrders SET status='FOR RELEASING' WHERE order_id= '" + row["order_id"] + "' ";
            }


            // Good Stocks
            // Move from Storage to Staging out

            // Update Transaction Ledger
            {
                DataTable insDT = LedgerSupport.GetLocationLedgerDT();

                insDT.Rows.Add("STAGING-OUT", now, "IN", "PICKLIST_DECLARE_INCOMPLETE", picklist_id);

                sql += LedgerSupport.UpdateLocationLedger(insDT);


                DataTable outsDT = LedgerSupport.GetLocationLedgerDT();

                foreach (DataGridViewRow row in scanned_grid.Rows)
                {
                    outsDT.Rows.Add(row.Cells["original_location"].Value, now, "OUT", "PICKLIST_DECLARE_INCOMPLETE", picklist_id);
                }

                sql += LedgerSupport.UpdateLocationLedger(outsDT);
            }



            // Update Location Products Ledger
            {
                DataTable insDT = LedgerSupport.GetLocationProductsLedgerDT();

                foreach (DataGridViewRow row in scanned_grid.Rows)
                {
                    insDT.Rows.Add("STAGING-OUT", row.Cells["product"].Value, row.Cells["qty"].Value, row.Cells["uom"].Value, row.Cells["lot_no"].Value, row.Cells["expiry"].Value);
                }
                sql += LedgerSupport.UpdateLocationProductsLedger(insDT);

                DataTable outsDT = LedgerSupport.GetLocationProductsLedgerDT();

                foreach (DataGridViewRow row in scanned_grid.Rows)
                {
                    outsDT.Rows.Add(row.Cells["original_location"].Value, row.Cells["product"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, row.Cells["uom"].Value, row.Cells["lot_no"].Value, row.Cells["expiry"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, int.Parse(row.Cells["qty"].Value.ToString()) * -1);
                }
                sql += LedgerSupport.UpdateLocationProductsLedger(outsDT);
            }



            // Missing / Bad Stocks



            // Specify if it's missing or bad
            MissingOrBadGridWindow dialog = new MissingOrBadGridWindow();


            foreach (DataGridViewRow row in picklist_details_grid.Rows)
            {
                int qty = int.Parse(row.Cells["Quantity"].Value.ToString());

                for (int i = 0; i < qty; i++)
                {
                    int index = dialog.header_grid.Rows.Add(
                        row.Cells["Product"].Value.ToString()
                        , row.Cells["Uom"].Value.ToString()
                        , row.Cells["Lot No"].Value.ToString()
                        , row.Cells["Expiry"].Value.ToString()
                        , row.Cells["Location"].Value.ToString()
                        , "1"
                        );
                    var new_row = dialog.header_grid.Rows[index];
                }
            }


            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }


            // For missing, Subtract from location and add a for resolutions - SHORTAGE


            foreach (DataGridViewRow row in dialog.header_grid.Rows)
            {
                if (row.Cells["what_happened"].Value.ToString() == "MISSING")
                {
                    has_missing = true;

                    // Update Transaction Ledger
                    {
                        DataTable outsDT = LedgerSupport.GetLocationLedgerDT();
                        outsDT.Rows.Add(row.Cells["location"].Value, now, "OUT", "PICKLIST_DECLARE_INCOMPLETE", picklist_id);
                        sql += LedgerSupport.UpdateLocationLedger(outsDT);
                    }

                    // Update Location Products Ledger
                    {
                        DataTable outsDT = LedgerSupport.GetLocationProductsLedgerDT();
                        outsDT.Rows.Add(row.Cells["location"].Value, row.Cells["product"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, row.Cells["uom"].Value, row.Cells["lot_no"].Value, row.Cells["expiry"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, int.Parse(row.Cells["qty"].Value.ToString()) * -1);
                        sql += LedgerSupport.UpdateLocationProductsLedger(outsDT);
                    }

                    // Update For Resolution
                    sql += DataSupport.GetInsert("ForResolutions", Utils.ToDict(
                                                     "trans_source", "PICKLIST_DECLARE_INCOMPLETE"
                                                     , "trans_id", picklist_id
                                                     , "detected_on", now
                                                     , "product", row.Cells["product"].Value
                                                     , "uom", row.Cells["uom"].Value
                                                     , "lot_no", row.Cells["lot_no"].Value
                                                     , "expiry", row.Cells["expiry"].Value
                                                     , "location", row.Cells["location"].Value.ToString()
                                                     , "variance_type", "SHORTAGE"
                                                     , "variance_qty", row.Cells["qty"].Value
                                                     , "status", "FOR RESOLUTION"
                                                     , "line", dialog.header_grid.Rows.IndexOf(row) + 1
                                                     ));
                }
            }



            // For bad stocks, Move it to bad stock storage and add a for resolutions - BAD STOCK
            // Add a for resolutions - ORDERS
            {
                ChooseBadStockLocationWindow grid_dialog = new ChooseBadStockLocationWindow();

                foreach (DataGridViewRow row in dialog.header_grid.Rows)
                {
                    if (row.Cells["what_happened"].Value.ToString() == "BAD STOCKS")
                    {
                        has_bad_stocks = true;
                        int index = grid_dialog.header_grid.Rows.Add(
                            row.Cells["Product"].Value.ToString()
                            , row.Cells["Uom"].Value.ToString()
                            , row.Cells["lot_no"].Value.ToString()
                            , row.Cells["Expiry"].Value.ToString()
                            , row.Cells["Location"].Value.ToString()
                            , "1"
                            );
                    }
                }


                if (grid_dialog.header_grid.Rows.Count > 0)
                {
                    if (grid_dialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }


                    foreach (DataGridViewRow row in grid_dialog.header_grid.Rows)
                    {
                        // Update the Printout
                        BadStockDT.Rows.Add(
                            row.Cells["location"].Value.ToString()
                            , row.Cells["product"].Value.ToString()
                            , row.Cells["uom"].Value.ToString()
                            , row.Cells["lot_no"].Value.ToString()
                            , row.Cells["expiry"].Value.ToString()
                            , row.Cells["qty"].Value.ToString()
                            , row.Cells["reason"].Value.ToString()
                            , row.Cells["bad_stock_location"].Value.ToString()
                            );


                        // Update Transaction Ledger
                        {
                            DataTable outsDT = LedgerSupport.GetLocationLedgerDT();
                            outsDT.Rows.Add(row.Cells["location"].Value, now, "OUT", "PICKLIST_DECLARE_INCOMPLETE", picklist_id);
                            sql += LedgerSupport.UpdateLocationLedger(outsDT);

                            DataTable insDT = LedgerSupport.GetLocationLedgerDT();
                            insDT.Rows.Add(row.Cells["bad_stock_location"].Value, now, "IN", "PICKLIST_DECLARE_INCOMPLETE", picklist_id);
                            sql += LedgerSupport.UpdateLocationLedger(insDT);
                        }

                        // Update Location Products Ledger
                        {
                            DataTable outsDT = LedgerSupport.GetLocationProductsLedgerDT();
                            outsDT.Rows.Add(row.Cells["location"].Value, row.Cells["product"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, row.Cells["uom"].Value, row.Cells["lot_no"].Value, row.Cells["expiry"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, int.Parse(row.Cells["qty"].Value.ToString()) * -1);
                            sql += LedgerSupport.UpdateLocationProductsLedger(outsDT);


                            DataTable insDT = LedgerSupport.GetLocationProductsLedgerDT();
                            insDT.Rows.Add(row.Cells["bad_stock_location"].Value, row.Cells["product"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * 1, row.Cells["uom"].Value, row.Cells["lot_no"].Value, row.Cells["expiry"].Value);
                            sql += LedgerSupport.UpdateLocationProductsLedger(insDT);
                        }

                        // Update For Resolution
                        sql += DataSupport.GetInsert("ForResolutions", Utils.ToDict(
                                                         "trans_source", "PICKLIST_DECLARE_INCOMPLETE"
                                                         , "trans_id", picklist_id
                                                         , "detected_on", now
                                                         , "product", row.Cells["product"].Value
                                                         , "uom", row.Cells["uom"].Value
                                                         , "lot_no", row.Cells["lot_no"].Value
                                                         , "expiry", row.Cells["expiry"].Value
                                                         , "location", row.Cells["location"].Value.ToString()
                                                         , "variance_type", "BAD STOCKS"
                                                         , "variance_qty", row.Cells["qty"].Value
                                                         , "status", "FOR RESOLUTION"
                                                         , "line", dialog.header_grid.Rows.IndexOf(row) + 1
                                                         ));
                    }
                }
            }



            {
                OrderHoldingWindow order_dialog = new OrderHoldingWindow();
                order_dialog.BadStockDT = BadStockDT;
                order_dialog.parent     = this;

                foreach (DataGridViewRow row in picklist_details_grid.Rows)
                {
                    order_dialog.products_grid.Rows.Add(
                        row.Cells["product"].Value.ToString()
                        , row.Cells["Uom"].Value.ToString()
                        , row.Cells["expiry"].Value.ToString()
                        , row.Cells["Lot No"].Value.ToString()
                        , row.Cells["Quantity"].Value.ToString()
                        , "0"
                        );
                }

                foreach (DataGridViewRow scanned_row in scanned_grid.Rows)
                {
                    foreach (DataGridViewRow row in order_dialog.products_grid.Rows)
                    {
                        if (row.Cells["product"].Value.ToString() == scanned_row.Cells["product"].Value.ToString() &&
                            row.Cells["uom"].Value.ToString() == scanned_row.Cells["uom"].Value.ToString() &&
                            row.Cells["expiry"].Value.ToString() == scanned_row.Cells["expiry"].Value.ToString() &&
                            row.Cells["lot_no"].Value.ToString() == scanned_row.Cells["lot_no"].Value.ToString()

                            )
                        {
                            row.Cells["qty_ordered"].Value = int.Parse(row.Cells["qty_ordered"].Value.ToString()) + int.Parse(scanned_row.Cells["qty"].Value.ToString());
                            row.Cells["qty_picked"].Value  = scanned_row.Cells["qty"].Value.ToString();
                        }
                    }
                }


                if (order_dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // Update Order Status for Orders put on hold
                DataTable order_compromisedDT = GetMergedOrders(order_dialog);

                foreach (DataRow row in order_compromisedDT.Rows)
                {
                    if (row["Status"].ToString() == "HOLD")
                    {
                        String reason = "";
                        if (has_bad_stocks && has_missing)
                        {
                            reason = "MISSING, BAD STOCK";
                        }
                        else if (has_missing)
                        {
                            reason = "MISSING";
                        }
                        else if (has_bad_stocks)
                        {
                            reason = "BAD STOCK";
                        }

                        sql += " UPDATE ReleaseOrders SET status='FOR RESOLUTION', holding_transaction='" + picklist_id + "', holding_datetime='" + now + "', holding_reason='" + reason + "' WHERE order_id= '" + row["Order ID"] + "' ";
                    }
                }
            }



            DataSupport.RunNonQuery(sql, IsolationLevel.ReadCommitted);
            MessageBox.Show("Success");
            this.Close();
        }
        private void SaveData()
        {
            String   putaway_id = DataSupport.GetNextMenuCodeInt("PA");
            DateTime now        = DateTime.Now;

            // Save Transaction
            String sql = DataSupport.GetInsert("Putaways", Utils.ToDict(
                                                   "putaway_id", putaway_id
                                                   , "container", parent.cboContainer.SelectedValue.ToStringNull()
                                                   , "encoded_on", now
                                                   ));

            foreach (DataGridViewRow row in parent.headerGrid.Rows)
            {
                sql += DataSupport.GetInsert("PutawayDetails", Utils.ToDict(
                                                 "putaway", putaway_id
                                                 , "product", row.Cells["product"].Value.ToString()
                                                 , "expected_qty", row.Cells["Quantity"].Value.ToString()
                                                 , "uom", row.Cells["uom"].Value.ToString()
                                                 , "lot_no", row.Cells["lot"].Value.ToString()
                                                 , "expiry", row.Cells["expiry"].Value.ToString()
                                                 , "location", row.Cells["location"].Value.ToString()
                                                 ));
            }


            // Update Transaction Ledger
            {
                // Out with the staging in
                DataTable outsDT = LedgerSupport.GetLocationLedgerDT();
                outsDT.Rows.Add("STAGING-IN", now, "OUT", "PUTAWAY", putaway_id);

                sql += LedgerSupport.UpdateLocationLedger(outsDT);


                // In with the container
                DataTable insDT = LedgerSupport.GetLocationLedgerDT();
                foreach (DataGridViewRow row in parent.headerGrid.Rows)
                {
                    insDT.Rows.Add(parent.cboContainer.SelectedValue.ToStringNull(), now, "IN", "PUTAWAY", putaway_id);
                }
                sql += LedgerSupport.UpdateLocationLedger(insDT);
            }

            // Update Location Products Ledger
            {
                // Out with the staging in
                DataTable outsDT = LedgerSupport.GetLocationProductsLedgerDT();

                foreach (DataGridViewRow row in parent.headerGrid.Rows)
                {
                    outsDT.Rows.Add("STAGING-IN", row.Cells["product"].Value, int.Parse(row.Cells["Quantity"].Value.ToString()) * -1, row.Cells["uom"].Value, row.Cells["lot"].Value, row.Cells["expiry"].Value);
                }
                sql += LedgerSupport.UpdateLocationProductsLedger(outsDT);


                // In with the container
                DataTable insDT = LedgerSupport.GetLocationProductsLedgerDT();

                foreach (DataGridViewRow row in parent.headerGrid.Rows)
                {
                    insDT.Rows.Add(parent.cboContainer.SelectedValue.ToStringNull(), row.Cells["product"].Value, row.Cells["Quantity"].Value, row.Cells["uom"].Value, row.Cells["lot"].Value, row.Cells["expiry"].Value);
                }
                sql += LedgerSupport.UpdateLocationProductsLedger(insDT);
            }



            try
            {
                DataSupport.RunNonQuery(sql, IsolationLevel.ReadCommitted);

                MessageBox.Show("Success");

                webBrowser1.DocumentText = webBrowser1.DocumentText.Replace("(issued on save)", putaway_id);
                btnPrintPreview.Text     = "Print";
                btnCancel.Visible        = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void DeclareComplete()
        {
            String   sql         = "";
            String   picklist_id = txtPicklist.Text;
            DateTime now         = DateTime.Now;



            // Update Picklist
            sql += "UPDATE Picklists SET status = 'DECLARED COMPLETE' WHERE picklist_id= '" + picklist_id + "'; ";

            DataTable order_ids = FAQ.GetOrdersFromPicklist(picklist_id);

            // Update Order Status
            foreach (DataRow row in order_ids.Rows)
            {
                sql += " UPDATE ReleaseOrders SET status='FOR RELEASING' WHERE order_id= '" + row["order_id"] + "' ";
            }


            // Update Transaction Ledger
            {
                DataTable insDT = LedgerSupport.GetLocationLedgerDT();

                insDT.Rows.Add("STAGING-OUT", now, "IN", "PICKLIST_DECLARE_COMPLETE", picklist_id);
                sql += LedgerSupport.UpdateLocationLedger(insDT);


                DataTable outsDT = LedgerSupport.GetLocationLedgerDT();

                foreach (DataGridViewRow row in scanned_grid.Rows)
                {
                    outsDT.Rows.Add(row.Cells["original_location"].Value, now, "OUT", "PICKLIST_DECLARE_COMPLETE", picklist_id);
                }

                sql += LedgerSupport.UpdateLocationLedger(outsDT);
            }



            // Update Location Products Ledger
            {
                DataTable insDT = LedgerSupport.GetLocationProductsLedgerDT();

                foreach (DataGridViewRow row in scanned_grid.Rows)
                {
                    insDT.Rows.Add("STAGING-OUT", row.Cells["product"].Value, row.Cells["qty"].Value, row.Cells["uom"].Value, row.Cells["lot_no"].Value, row.Cells["expiry"].Value);
                }
                sql += LedgerSupport.UpdateLocationProductsLedger(insDT);

                DataTable outsDT = LedgerSupport.GetLocationProductsLedgerDT();

                foreach (DataGridViewRow row in scanned_grid.Rows)
                {
                    outsDT.Rows.Add(row.Cells["original_location"].Value, row.Cells["product"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, row.Cells["uom"].Value, row.Cells["lot_no"].Value, row.Cells["expiry"].Value, int.Parse(row.Cells["qty"].Value.ToString()) * -1, int.Parse(row.Cells["qty"].Value.ToString()) * -1);
                }
                sql += LedgerSupport.UpdateLocationProductsLedger(outsDT);
            }



            DataSupport.RunNonQuery(sql, IsolationLevel.ReadCommitted);
            MessageBox.Show("Success");
            this.Close();
        }
Ejemplo n.º 4
0
        private void txtScan_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                var product_row = BarcodeSupport.GetProductFromBarcode(txtScan.Text);
                if (product_row == null)
                {
                    MessageBox.Show("Barcode Not Recognized");
                    return;
                }
                String product = product_row["PRODUCT"].ToString();
                String uom     = product_row["MATCHED_UOM"].ToString();

                DataTable dt = DataSupport.RunDataSet("SELECT order_id[Order], Product, Expiry, lot_no[Lot No], order_qty[Order Qty], Uom, Scanned_qty[Scanned Qty], scanned_on [Scanned On] FROM ReleaseDetailItems WHERE release = @release AND order_id = @order_id AND product=@product AND @uom = @uom", "release", release_id, "order_id", current_order, "product", product, "uom", uom).Tables[0];

                SelectGridWindow dialog = new SelectGridWindow();
                dialog.dataGridView1.DataSource = dt;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var selected_row = dialog.dataGridView1.SelectedRows[0];

                String expiry = selected_row.Cells["Expiry"].Value.ToString();
                String lot_no = selected_row.Cells["Lot No"].Value.ToString();


                String sql = "";

                sql += " UPDATE ReleaseDetailItems SET Scanned_qty = Scanned_qty +1 WHERE release = '" + release_id + "' AND order_id = '" + current_order + "' AND product='" + product + "' AND uom = '" + uom + "' AND expiry = '" + expiry + "' AND lot_no='" + lot_no + "'  ";


                // Update Transaction Ledger
                {
                    // Out with the location
                    DataTable outsDT = LedgerSupport.GetLocationLedgerDT();

                    outsDT.Rows.Add("STAGING-OUT", now, "OUT", "RELEASE", release_id);

                    sql += LedgerSupport.UpdateLocationLedger(outsDT);

                    // In with both Staging out and for resolution
                    DataTable insDT = LedgerSupport.GetLocationLedgerDT();

                    insDT.Rows.Add("RELEASED", now, "IN", "PICKLIST_DECLARE_COMPLETE", release_id);
                    sql += LedgerSupport.UpdateLocationLedger(insDT);
                }
                // Update Location Products Ledger
                {
                    // Out with the staging out
                    DataTable outsDT = LedgerSupport.GetLocationProductsLedgerDT();

                    outsDT.Rows.Add("STAGING-OUT", product, -1, uom, lot_no, expiry);


                    sql += LedgerSupport.UpdateLocationProductsLedger(outsDT);

                    DataTable insDT = LedgerSupport.GetLocationProductsLedgerDT();
                    insDT.Rows.Add("RELEASED", product, 1, uom, lot_no, expiry);


                    sql += LedgerSupport.UpdateLocationProductsLedger(insDT);
                }

                DataSupport.RunNonQuery(sql, IsolationLevel.ReadCommitted);

                SynchroSupport.UpdateOrderStatus(release_id);
                LoadData();
            }
        }