Exemplo n.º 1
0
        private void PostInvoice()
        {
            try
            {
                decimal decTotalAmount = Convert.ToDecimal(lblTotalAmount.Text);

                if (decTotalAmount == 0)
                {
                    decimal decTotalDebitAmount = Convert.ToDecimal(lblTotalDebitAmount.Text);

                    foreach (DataListItem item in lstPO.Items)
                    {
                        HtmlInputCheckBox chkList = (HtmlInputCheckBox)item.FindControl("chkList");
                        if (chkList != null)
                        {
                            if (chkList.Checked == true)
                            {
                                Label lblUnpaidAmount = (Label)item.FindControl("lblUnpaidAmount");
                                decimal decUnpaidAmount = Convert.ToDecimal(lblUnpaidAmount.Text);

                                if (decTotalDebitAmount == 0)
                                { break; }
                                else if (decTotalDebitAmount >= decUnpaidAmount)
                                { decTotalDebitAmount -= decUnpaidAmount; }
                                else if (decTotalDebitAmount != 0)
                                { decTotalDebitAmount = 0; break; }
                            }
                        }
                    }
                    if (decTotalDebitAmount > 0)
                    {
                        lblReferrer.Text = "Warning!!! Cannot save the transaction, the Total Amount is greater than the payable amount.";
                        string stScript = "<Script>";
                        stScript += "window.alert('Warning!!! Cannot save the transaction, the Total Amount is greater than the payable amount.\n Check more Purchase Order(s) to be paid or decrease the Total debit/credit Amount.')";
                        stScript += "</Script>";
                        Response.Write(stScript);
                    }
                    else
                    {
                        decTotalDebitAmount = Convert.ToDecimal(lblTotalDebitAmount.Text);
                        DateTime PostingDate = Convert.ToDateTime(txtPostingDate.Text + " " + DateTime.Now.ToString("HH:mm"));
                        long lPaymentID = Convert.ToInt64(lblPaymentID.Text);
                        Payments clsPayments = new Payments();
                        clsPayments.GetConnection();

                        PaymentPODetailDetails clsPaymentPODetailDetails;

                        PaymentPODetails clsPaymentPODetails = new PaymentPODetails(clsPayments.Connection, clsPayments.Transaction);
                        PO clsPO = new PO(clsPayments.Connection, clsPayments.Transaction);

                        foreach (DataListItem item in lstPO.Items)
                        {
                            HtmlInputCheckBox chkList = (HtmlInputCheckBox)item.FindControl("chkList");
                            if (chkList != null)
                            {
                                 if (chkList.Checked == true)
                                {
                                    long lPOID = Convert.ToInt64(chkList.Value);
                                    clsPaymentPODetailDetails = new PaymentPODetailDetails();
                                    clsPaymentPODetailDetails.PaymentID = lPaymentID;
                                    clsPaymentPODetailDetails.POID = lPOID;

                                    Label lblUnpaidAmount = (Label)item.FindControl("lblUnpaidAmount");
                                    decimal decUnpaidAmount = Convert.ToDecimal(lblUnpaidAmount.Text);

                                    if (decTotalDebitAmount == 0)
                                    { break; }
                                    else if (decTotalDebitAmount >= decUnpaidAmount)
                                    {
                                        clsPO.UpdatePayment(lPOID, decUnpaidAmount, POPaymentStatus.FullyPaid);

                                        clsPaymentPODetailDetails.Amount = decUnpaidAmount;
                                        clsPaymentPODetailDetails.PaymentStatus = POPaymentStatus.FullyPaid;
                                        clsPaymentPODetails.Insert(clsPaymentPODetailDetails);

                                        decTotalDebitAmount -= decUnpaidAmount;
                                    }
                                    else if (decTotalDebitAmount != 0)
                                    {
                                        clsPO.UpdatePayment(lPOID, decTotalDebitAmount, POPaymentStatus.Partially);

                                        clsPaymentPODetailDetails.Amount = decTotalDebitAmount;
                                        clsPaymentPODetailDetails.PaymentStatus = POPaymentStatus.Partially;
                                        clsPaymentPODetails.Insert(clsPaymentPODetailDetails);

                                        decTotalDebitAmount = 0;
                                    }

                                }
                            }
                        }

                        clsPayments.Post(lPaymentID, PostingDate);
                        clsPayments.CommitAndDispose();

                        Response.Redirect("Default.aspx?task=" + Common.Encrypt("list", Session.SessionID));
                    }
                }
                else
                {
                    //lblReferrer.Text = "Cannot post invoice, the debit/credit amount should be equal. Please check the posted accounts.";
                    string stScript = "<Script>";
                    stScript += "window.alert('Cannot post invoice, the debit/credit amount should be equal. Please check the posted accounts.')";
                    stScript += "</Script>";
                    Response.Write(stScript);
                }
            }
            catch (Exception ex) {
                lblReferrer.Text= "'Cannot post invoice. unexpected error occurred: " + ex.ToString();
                string stScript = "<Script>";
                stScript += "window.alert('Cannot post invoice. unexpected error occurred: " + ex.ToString() + "')" ;
                stScript += "</Script>";
                Response.Write(stScript);
            }
        }
Exemplo n.º 2
0
        private void LoadPO()
        {
            long PaymentID = Convert.ToInt64(lblPaymentID.Text);

            DataClass clsDataClass = new DataClass();

            PaymentPODetails clsPaymentPODetails = new PaymentPODetails();
            lstPO.DataSource = clsDataClass.DataReaderToDataTable(clsPaymentPODetails.List(PaymentID, "PaymentDetailID", SortOption.Ascending)).DefaultView;
            lstPO.DataBind();
            clsPaymentPODetails.CommitAndDispose();

            Label lblAmount;

            decimal decAmount = 0;

            foreach (DataListItem item in lstPO.Items)
            {
                lblAmount = (Label)item.FindControl("lblAmount");
                decAmount += Convert.ToDecimal(lblAmount.Text);
            }

            lblPOTotalAmount.Text = decAmount.ToString("#,##0.#0");
        }