Exemplo n.º 1
0
        private void grdList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex < 0)
                {
                    return;
                }
                DocumentUnlockDB dudb       = new DocumentUnlockDB();
                string           columnName = grdList.Columns[e.ColumnIndex].Name;
                if (columnName.Equals("Unlock"))
                {
                    prevdc.TemporaryNo   = Convert.ToInt32(grdList.Rows[e.RowIndex].Cells["TempNo"].Value);
                    prevdc.TemporaryDate = Convert.ToDateTime(grdList.Rows[e.RowIndex].Cells["TempDate"].Value);
                    prevdc.TableName     = grdList.Rows[e.RowIndex].Cells["TableName"].Value.ToString();

                    string frwdList = grdList.Rows[e.RowIndex].Cells["ForwarderList"].Value.ToString();
                    if (frwdList == null)
                    {
                        MessageBox.Show("Failed to retrive Forwardlist");
                        return;
                    }
                    DialogResult dialog = MessageBox.Show("Are you sure to Unlock the document ?\n\nDocument Type\t:  " +
                                                          selectedDocName + "\nTemporary No\t:  " + prevdc.TemporaryNo + "\nTemprary Date\t:  " + prevdc.TemporaryDate.ToString("yyyy-MM-dd") + "\n"
                                                          , "Confirmation", MessageBoxButtons.YesNo);
                    if (dialog == DialogResult.No)
                    {
                        return;
                    }
                    string[] strArr  = frwdList.Split(Main.delimiter2);
                    int      DocStat = strArr.Count();
                    ////if document is MRN, do not reverse if any issue from the MRN.
                    ////if Invoice out, reverse all quantity before reversing the document
                    if (selectedDocID == "MRN")
                    {
                        if (MRNHeaderDB.checkForIssuesFromMRN(prevdc.TemporaryNo, prevdc.TemporaryDate))
                        {
                            //no issues (purchase return and Invoice) from MRN

                            MessageBox.Show("Stock has been issued from MRN. Reversal request denied");
                            return;
                        }
                        else
                        {
                            if (dudb.updateDocForUnlockingMRN(prevdc, DocStat))
                            {
                                MessageBox.Show("Document Unlocked with Updating Stock sucessfully.");
                                grdList.Rows.RemoveAt(e.RowIndex);
                                return;
                            }
                            else
                            {
                                MessageBox.Show("Document Failed to Unlocked");
                                return;
                            }
                        }
                    }
                    else if (selectedDocID == "POPRODUCTINWARD" || selectedDocID == "POSERVICEINWARD")
                    {
                        string result = POPIHeaderDB.checkForInvoiceIssuesForPOPI(prevdc.TemporaryNo, prevdc.TemporaryDate, selectedDocID);
                        if (result == "error" || result.Length != 0)
                        {
                            if (result == "error")
                            {
                                return;
                            }
                            //Inivoice Prepared For this PO
                            string   InvPrepared = "";
                            string[] invArr      = result.Split(Main.delimiter1);
                            foreach (string str in invArr)
                            {
                                if (str.Length != 0)
                                {
                                    string[] invNoDate = str.Split(';');
                                    InvPrepared = InvPrepared + "\nTemporary No: " + invNoDate[0] + "    Temporary Date: " + Convert.ToDateTime(invNoDate[1]).ToString("yyyy-MM-dd");
                                }
                            }
                            MessageBox.Show("Inivoice Prepared For this PO. Reversal request denied.\n" + InvPrepared, "Invoice Prepared Details");
                            return;
                        }
                        else
                        {
                            if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID))
                            {
                                MessageBox.Show("PO Document Unlocked");
                                grdList.Rows.RemoveAt(e.RowIndex);
                                return;
                            }
                            else
                            {
                                MessageBox.Show("Failed to unlock Document");
                                return;
                            }
                        }
                    }
                    else if (selectedDocID == "PRODUCTINVOICEOUT" || selectedDocID == "PRODUCTEXPORTINVOICEOUT" ||
                             selectedDocID == "SERVICEINVOICEOUT" || selectedDocID == "SERVICEEXPORTINVOICEOUT")
                    {
                        invoiceoutheader iohTemp = new invoiceoutheader();
                        iohTemp.TemporaryNo   = prevdc.TemporaryNo;
                        iohTemp.TemporaryDate = prevdc.TemporaryDate;
                        iohTemp.DocumentID    = selectedDocID;
                        if (InvoiceOutHeaderDB.isInvoiceOutReceiptPreparedForInvOut(iohTemp))
                        {
                            MessageBox.Show("Receipt Adjusted against this Invoice . Not allowed to Unlock.");
                            return;
                        }
                        //return;
                        if (dudb.updateDocForUnlockingInvoiceOUT(prevdc, DocStat, selectedDocID))
                        {
                            if (selectedDocID == "PRODUCTINVOICEOUT" || selectedDocID == "PRODUCTEXPORTINVOICEOUT")
                            {
                                MessageBox.Show("Document Unlocked with Updating Stock sucessfully.");
                            }
                            else
                            {
                                MessageBox.Show("Document Unlocked sucessfully.");
                            }
                            grdList.Rows.RemoveAt(e.RowIndex);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Document Failed to Unlocked");
                            return;
                        }
                    }

                    else if (selectedDocID == "GTN")
                    {
                        if (GTNDB.checkForIssuesOfGTNInStock(prevdc.TemporaryNo, prevdc.TemporaryDate))
                        {
                            //no issues (purchase return and Invoice) from MRN

                            MessageBox.Show("Stock has been issued from GTN. Reversal request denied");
                            return;
                        }
                        else
                        {
                            if (dudb.updateDocForUnlockingGTN(prevdc, DocStat))
                            {
                                MessageBox.Show("Document Unlocked with Updating Stock sucessfully.");
                                grdList.Rows.RemoveAt(e.RowIndex);
                                return;
                            }
                            else
                            {
                                MessageBox.Show("Document Failed to Unlocked");
                                return;
                            }
                        }
                    }
                    else if (selectedDocID == "POINVOICEIN" || selectedDocID == "WOINVOICEIN" || selectedDocID == "POGENERALINVOICEIN")
                    {
                        invoiceinheader iihTemp = new invoiceinheader();
                        iihTemp.TemporaryNo   = prevdc.TemporaryNo;
                        iihTemp.TemporaryDate = prevdc.TemporaryDate;
                        iihTemp.DocumentID    = selectedDocID;
                        if (InvoiceInHeaderDB.isInvoiceInPaymentPreparedForInvIN(iihTemp))
                        {
                            MessageBox.Show("Payment Adjusted against this Invoice . Not allowed to Unlock.");
                            return;
                        }
                        if (dudb.updateDocForUnlockingInvoiceIN(prevdc, DocStat, selectedDocID))
                        {
                            MessageBox.Show("Document Unlocked");
                            grdList.Rows.RemoveAt(e.RowIndex);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Document Failed to Unlocked");
                            return;
                        }
                    }
                    else if (selectedDocID == "WORKORDER")
                    {
                        workorderheader wohtemp = new workorderheader();
                        wohtemp.TemporaryNo   = prevdc.TemporaryNo;
                        wohtemp.TemporaryDate = prevdc.TemporaryDate;
                        wohtemp.DocumentID    = selectedDocID;
                        workorderheader woh = WorkOrderDB.getWONOAndDateOFWO(wohtemp);
                        if (WorkOrderDB.isInvoicePreparedForWO(woh.WONo, woh.WODate))
                        {
                            MessageBox.Show("invoice received against this work order . Not allowed to Unlock.");
                            return;
                        }
                        if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID))
                        {
                            MessageBox.Show("Document Unlocked");
                            grdList.Rows.RemoveAt(e.RowIndex);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Document Failed to Unlocked");
                            return;
                        }
                    }
                    else if (selectedDocID == "PURCHASEORDER")
                    {
                        poheader pohtemp = new poheader();
                        pohtemp.TemporaryNo   = prevdc.TemporaryNo;
                        pohtemp.TemporaryDate = prevdc.TemporaryDate;
                        pohtemp.DocumentID    = selectedDocID;
                        poheader poh = PurchaseOrderDB.getPONOAndDateOFPOOut(pohtemp);
                        if (PurchaseOrderDB.isMRNPreparedForPO(poh.PONo, poh.PODate))
                        {
                            MessageBox.Show("MRN received against this Purchase order . Not allowed to Unlock.");
                            return;
                        }
                        if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID))
                        {
                            MessageBox.Show("Document Unlocked");
                            grdList.Rows.RemoveAt(e.RowIndex);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Document Failed to Unlocked");
                            return;
                        }
                    }
                    else if (selectedDocID == "POGENERAL")
                    {
                        pogeneralheader pohtemp = new pogeneralheader();
                        pohtemp.TemporaryNo   = prevdc.TemporaryNo;
                        pohtemp.TemporaryDate = prevdc.TemporaryDate;
                        pohtemp.DocumentID    = selectedDocID;
                        pogeneralheader poh = PurchaseOrderGeneralDB.getPONOAndDateOFPOGen(pohtemp);
                        if (PurchaseOrderGeneralDB.isInvoicePreparedForPOGeneral(poh.PONo, poh.PODate))
                        {
                            MessageBox.Show("invoice received against this Purchase order . Not allowed to Unlock.");
                            return;
                        }
                        if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID))
                        {
                            MessageBox.Show("Document Unlocked");
                            grdList.Rows.RemoveAt(e.RowIndex);
                            return;
                        }
                        else
                        {
                            MessageBox.Show("Document Failed to Unlocked");
                            return;
                        }
                    }
                    else if (dudb.updateDocForUnlocking(prevdc, DocStat, selectedDocID))
                    {
                        MessageBox.Show("Document Unlocked");
                        grdList.Rows.RemoveAt(e.RowIndex);
                    }
                    else
                    {
                        MessageBox.Show("Failed to unlock Document");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception : Failed to unlock Document");
            }
        }
Exemplo n.º 2
0
        private void btnView_Click(object sender, EventArgs e)
        {
            grdList.Visible = true;
            grdList.Rows.Clear();
            //------
            double totalPOValue = 0.0;
            double totalInvoiceValue = 0.0;
            double balanceAmount = 0.0, Invoiceamt = 0.0, Paymntamunt = 0.0;

            //------
            //pnlAddEdit.Visible = true;
            setButtonVisibility("Edit");
            try
            {
                StringBuilder query = new StringBuilder();

                query.Append("select TemporaryNo,TemporaryDate,PONo,PODate,CustomerName,ProductValueINR from ViewPOHeader ");
                if (cmbTrack.SelectedIndex != -1)
                {
                    string str = "where PODate >= '" + dtFrom.Value.ToString("yyyy-MM-dd") + "' and PODate <='" + dtTo.Value.ToString("yyyy-MM-dd") + "'";
                    if (cmbTrack.SelectedItem.ToString() == "Open")
                    {
                        str += "and Status=1 and DocumentStatus = 99";
                    }
                    else if (cmbTrack.SelectedItem.ToString() == "Closed")
                    {
                        str += " and Status=7 and DocumentStatus = 99";
                    }
                    else
                    {
                        str += "and Status in (1,7) and DocumentStatus = 99 ";
                    }
                    query.Append(str);
                }

                if (cmbCustomer.SelectedItem.ToString() != "All")
                {
                    query.Append(" and CustomerID='" + ((Structures.ComboBoxItem)cmbCustomer.SelectedItem).HiddenValue + "'");
                }
                query.Append(" Order by PONo,PODate");
                PurchaseOrderDB        popihdb     = new PurchaseOrderDB();
                InvoiceInHeaderDB      InvoDb      = new InvoiceInHeaderDB();
                PaymentVoucherDB       PaymtvDB    = new PaymentVoucherDB();
                List <poheader>        POPIHeaders = popihdb.ListPopiFilters2(query.ToString());
                List <MRNHeader2>      pop         = popihdb.getMRNHeaderdata();
                List <invoiceinheader> Invoices    = InvoDb.getInvoicedata();
                List <paymentvoucher>  Payments    = PaymtvDB.getPaymentdata();
                foreach (poheader popih in POPIHeaders)
                {
                    grdList.Rows.Add();
                    grdList.Rows[grdList.RowCount - 1].Cells["gTemporaryNo"].Value     = popih.TemporaryNo;
                    grdList.Rows[grdList.RowCount - 1].Cells["gTemporaryDate"].Value   = popih.TemporaryDate;
                    grdList.Rows[grdList.RowCount - 1].Cells["gTrackingNo"].Value      = popih.PONo;
                    grdList.Rows[grdList.RowCount - 1].Cells["gTrackingDate"].Value    = popih.PODate;
                    grdList.Rows[grdList.RowCount - 1].Cells["gCustomerName"].Value    = popih.CustomerName;
                    grdList.Rows[grdList.RowCount - 1].Cells["POValueINR"].Value       = popih.ProductValueINR;
                    grdList.Rows[grdList.RowCount - 1].Cells["TotalValueBilled"].Value = 0;
                    totalPOValue += popih.ProductValueINR;
                    if (popih.PONo != 0 && popih.PODate != DateTime.MinValue)
                    {
                        var        results = pop.Where(oh => oh.PONos.Contains("" + popih.PONo + "") && oh.PODates.Contains("" + popih.PODate.ToString("yyyy-MM-dd") + "")).ToList();
                        int[]      MRNNos  = results.Select(i => i.MRNNo).ToArray();
                        DateTime[] MrnDats = results.Select(i => i.MRNDate).ToArray();
                        var        AVC     = from x in Invoices
                                             where MRNNos.Contains(x.MRNNo) && MrnDats.Contains(x.MRNDate)
                                             select x;
                        string [] ABCCD = AVC.Select(i => i.DocumentID.ToString() + Main.delimiter1 + i.DocumentNo.ToString() + Main.delimiter1 + i.DocumentDate.ToString("yyyy-MM-dd") + Main.delimiter2).ToArray();
                        var       AVC2  = from x in Payments
                                          where ABCCD.Contains(x.BillDetails)
                                          select x;

                        double iamt = results.Sum(item => item.MRNValue);
                        Invoiceamt  = AVC.Sum(item => item.InvoiceValueINR);
                        Paymntamunt = AVC2.Sum(item => Convert.ToDouble(item.VoucherAmountINR));


                        grdList.Rows[grdList.RowCount - 1].Cells["TotalValueBilled"].Value = iamt;
                        totalInvoiceValue += iamt;
                    }
                    balanceAmount = Convert.ToDouble(grdList.Rows[grdList.RowCount - 1].Cells["POValueINR"].Value) - Convert.ToDouble(grdList.Rows[grdList.RowCount - 1].Cells["TotalValueBilled"].Value);
                    grdList.Rows[grdList.RowCount - 1].Cells["BalanceAmount"].Value = balanceAmount;
                    grdList.Rows[grdList.RowCount - 1].Cells["InvoiceAmt"].Value    = Invoiceamt;
                    grdList.Rows[grdList.RowCount - 1].Cells["Payamt"].Value        = Paymntamunt;
                    grdList.Rows[grdList.RowCount - 1].Cells["AmtBalance"].Value    = Invoiceamt - Paymntamunt;;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in PO Product Inward Report Listing");
                grdList.Rows.Clear();
            }
            if (grdList.Rows.Count <= 0)
            {
                btnExportToExcel.Visible = false;
                grdList.Visible          = false;
                pnlTotal.Visible         = false;
                MessageBox.Show("No Data to Show");
            }
            else
            {
                lblPOValue.Text      = Math.Round(totalPOValue / 100000, 2).ToString() + " Lakhs";
                lblBilledValue.Text  = Math.Round(totalInvoiceValue / 100000, 2).ToString() + " Lakhs";
                lblBalanceValue.Text = Math.Round((totalPOValue - totalInvoiceValue) / 100000, 2).ToString() + " Lakhs";
                lblPOCount.Text      = " PO Count:" + grdList.Rows.Count;
                pnlTotal.Visible     = true;
            }
        }
Exemplo n.º 3
0
        private void ShowAllDetails()
        {
            try
            {
                InvoiceInHeaderDB pdb = new InvoiceInHeaderDB();
                invoiceinheader   iih = new invoiceinheader();
                iih.DocumentID    = docID;
                iih.TemporaryNo   = tempno;
                iih.TemporaryDate = tempdate;
                invoiceinheader poh = pdb.getFilteredInvoiceInHeaderList(docID, tempno, tempdate).FirstOrDefault();
                payList = InvoiceInHeaderDB.getInvoiceInAdvPaymentDetails(tempno, tempdate, docID);
                decimal TotalAdv = payList.Sum(pay => pay.Amount);

                expList = InvoiceInHeaderDB.getExpenseDetialForInvoiceIN(iih);
                decimal TotalExp = expList.Sum(exp => exp.Amount);
                if (poh != null)
                {
                    txtDocID.Text              = poh.DocumentID;
                    txtMRNno.Text              = poh.MRNNo.ToString();
                    dtMRNDate.Value            = poh.MRNDate;
                    txtSupInvceNo.Text         = poh.SupplierInvoiceNo.ToString();
                    dtSuplrInvcDate.Value      = poh.SupplierInvoiceDate;
                    txtDocNo.Text              = poh.DocumentNo.ToString();
                    dtDocDate.Value            = poh.DocumentDate;
                    cmbCustomer.SelectedIndex  = Structures.ComboFUnctions.getComboIndex(cmbCustomer, poh.CustomerID);
                    txtAdvncPaymntVoucher.Text = TotalAdv.ToString();
                    txtExpenses.Text           = TotalExp.ToString();
                    cmbCurrency.SelectedIndex  = Structures.ComboFUnctions.getComboIndex(cmbCurrency, poh.CurrencyID);
                    txtFreightCharge.Text      = poh.FreightCharge.ToString();
                    txtproductValue.Text       = poh.ProductValueINR.ToString();
                    txtTaxvalue.Text           = poh.ProductTaxINR.ToString();
                    txtInvoicevalue.Text       = poh.InvoiceValueINR.ToString();
                    if (poh.PONos != "")
                    {
                        txtPONo.Text    = poh.PONos.ToString();
                        txtPODates.Text = poh.PODates;
                    }
                }
                invoiceinheader popd = new invoiceinheader();
                popd.DocumentID    = docID;
                popd.TemporaryNo   = tempno;
                popd.TemporaryDate = tempdate;
                List <invoiceindetail> pod = InvoiceInHeaderDB.getInvoiceDetail(popd);
                grdPRDetail.Rows.Clear();
                int    i     = 0;
                double count = 0;
                foreach (invoiceindetail po in pod)
                {
                    grdPRDetail.Rows.Add();
                    grdPRDetail.Rows[i].Cells["LineNo"].Value   = grdPRDetail.Rows.Count;
                    grdPRDetail.Rows[i].Cells["Item"].Value     = po.StockItemID;
                    grdPRDetail.Rows[i].Cells["ItemDesc"].Value = po.StockItemName;
                    grdPRDetail.Rows[i].Cells["TaxCode"].Value  = po.TaxCode;
                    grdPRDetail.Rows[i].Cells["Quantity"].Value = po.Quantity;
                    grdPRDetail.Rows[i].Cells["Price"].Value    = po.Price;
                    grdPRDetail.Rows[i].Cells["Tax"].Value      = po.Tax;
                    double valu = po.Price * po.Quantity + po.Tax;
                    grdPRDetail.Rows[i].Cells["Value"].Value = valu;
                    count += valu;
                    i++;
                }
                txtTotalValue.Text = count.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in POOut");
            }
        }