Ejemplo n.º 1
0
        private void btnFinalize_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmPurchaseOrder", "Finalize"))
                {
                    return;
                }

                foreach (DataRow _drStatus in loPurchaseOrder.getPurchaseOrderStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    if (_drStatus[0].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Purchase Order is already FINALIZED!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }

                    /*
                     * if (_drStatus[4].ToString() == GlobalVariables.Username)
                     * {
                     *  MessageBoxUI _mbStatus = new MessageBoxUI("You cannot FINALIZE a Purchase Order you preprared!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                     *  _mbStatus.ShowDialog();
                     *  return;
                     * }
                     */
                    /*
                     * if (_drStatus["SRId"].ToString() == "")
                     * {
                     *  MessageBoxUI _mbStatus = new MessageBoxUI("Stocks Receiving must precedes finalization!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                     *  _mbStatus.ShowDialog();
                     *  return;
                     * }
                     */
                }
                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue finalizing this Purchase Order record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        if (loPurchaseOrder.finalize(dgvList.CurrentRow.Cells[0].Value.ToString()))
                        {
                            MessageBoxUI _mb1 = new MessageBoxUI("Purchase Order record has been successfully finalized!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                            _mb1.ShowDialog();
                            previewPurchaseOrderDetail(dgvList.CurrentRow.Cells[0].Value.ToString());
                            //sendEmailToCreator();
                            refresh();
                        }
                        else
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnFinalize_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnPost_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmGeneralJournal", "Post"))
                {
                    return;
                }

                foreach (DataRow _drStatus in loJournalEntry.getJournalEntryStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    if (_drStatus[0].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Journal Entry is already POSTED!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }

                    /*
                     * if (_drStatus[4].ToString() == GlobalVariables.Username)
                     * {
                     *  MessageBoxUI _mbStatus = new MessageBoxUI("You cannot POST a Journal Entry you preprared!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                     *  _mbStatus.ShowDialog();
                     *  return;
                     * }
                     */
                }
                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue posting this Journal Entry record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        try
                        {
                            if (loJournalEntry.post(dgvList.CurrentRow.Cells[0].Value.ToString()))
                            {
                                MessageBoxUI _mb1 = new MessageBoxUI("Journal Entry record has been successfully posted!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                                _mb1.ShowDialog();
                                previewDetail(dgvList.CurrentRow.Cells[0].Value.ToString());
                                //sendEmailToCreator();
                                refresh();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBoxUI mb = new MessageBoxUI(ex, GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            mb.ShowDialog();
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnPost_Click");
                em.ShowDialog();
                return;
            }
        }
        private void tsmiRequestToCheckAndPost_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmGeneralJournal", "Request to Check and Post"))
                {
                    return;
                }

                string pCompanyCode = "";
                foreach (DataRow _drStatus in loJournalEntry.getJournalEntryStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    pCompanyCode = _drStatus["Company"].ToString();
                    if (_drStatus[0].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("You cannot repost a posted Journal Entry!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                }

                /*
                 * foreach (DataRow _dr in loJournalEntry.getAccountantEmailAddress(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                 * {
                 *  string _form = dgvList.CurrentRow.Cells[5].Value.ToString();
                 *  string _bodyhead = "<h3>Journal Entry Id : " + dgvList.CurrentRow.Cells[0].Value.ToString() + "</h3>" +
                 *                  "<h4>Form : Journal Voucher</h4>" +
                 *                  "<h4>Company : " + dgvList.CurrentRow.Cells[3].Value.ToString() + "</h4>" +
                 *                  "<h4>Date Prepared : " + dgvList.CurrentRow.Cells[7].Value.ToString() + "</h4>" +
                 *                  "<h4>Explanation : " + dgvList.CurrentRow.Cells[8].Value.ToString() + "</h4>" +
                 *                  "<h4>Total Debit : " + dgvList.CurrentRow.Cells[9].Value.ToString() + "</h4>" +
                 *                  "<h4>Total Credit : " + dgvList.CurrentRow.Cells[10].Value.ToString() + "</h4>" +
                 *                  "<h4>Prepared By : " + dgvList.CurrentRow.Cells[16].Value.ToString() + "</h4>" +
                 *                  "</br> " +
                 *                  "<table border=\"1\">";
                 *
                 *  string _bodyDetailHeader = "<tr>" +
                 *                                  "<th>Account Code</th>" +//1
                 *                                  "<th>Account Title</th>" +//2
                 *                                  "<th>Debit</th>" +//3
                 *                                  "<th>Credit</th>" +//4
                 *                                  "<th>Subsidiary</th>" +//5
                 *                                  "<th>Description</th>" +//6
                 *                                  "<th>Remarks</th>" +//7
                 *                             "</tr>";
                 *  string _bodycontent = "";
                 *  foreach (DataRow _drbody in loJournalEntryDetail.getJournalEntryDetails(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                 *  {
                 *      _bodycontent += "<tr>" +
                 *                          "<td>" + _drbody[1].ToString() + "</td>" +
                 *                          "<td>" + _drbody[2].ToString() + "</td>" +
                 *                          "<td align=\"right\">" + string.Format("{0:n}", decimal.Parse(_drbody[3].ToString())) + "</td>" +
                 *                          "<td align=\"right\">" + string.Format("{0:n}", decimal.Parse(_drbody[4].ToString())) + "</td>" +
                 *                          "<td align=\"center\">" + _drbody[5].ToString() + "</td>" +
                 *                          "<td>" + _drbody[6].ToString() + "</td>" +
                 *                          "<td align=\"center\">" + _drbody[7].ToString() + "</td>" +
                 *                      "</tr>";
                 *  }
                 *
                 *  try
                 *  {
                 *      if (_dr[1].ToString() != "")
                 *      {
                 *          string[] emailAdd = _dr[1].ToString().Split(',');
                 *          for (int i = 0; i < emailAdd.Length; i++)
                 *          {
                 *              foreach (DataRow _dr1 in loJournalEntry.getCheckAccountantEmailAddress(emailAdd[i], pCompanyCode).Rows)
                 *              {
                 *                  if (int.Parse(_dr1[0].ToString()) > 0)
                 *                  {
                 *                      GlobalFunctions.SendEmail(emailAdd[i], "", "Request to Check and Post (J.E. Id : " + dgvList.CurrentRow.Cells[0].Value.ToString() + ")", _bodyhead + _bodyDetailHeader + _bodycontent);
                 *                  }
                 *              }
                 *          }
                 *      }
                 *  }
                 *  catch { }
                 * }*/
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "tsmiRequestToCheckAndPost_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (decimal.Parse(txtQtyOUT.Text) == 0)
                {
                    MessageBoxUI _mbStatus = new MessageBoxUI("Qty must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mbStatus.ShowDialog();
                    return;
                }

                lRecordData[0] = lDetailId;
                lRecordData[1] = lSODetailId;
                try
                {
                    lRecordData[2] = cboStockDescription.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mbStatus = new MessageBoxUI("You must select a correct Stock!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mbStatus.ShowDialog();
                    cboStockDescription.Focus();
                    return;
                }
                lRecordData[3] = txtStockCode.Text;
                lRecordData[4] = cboStockDescription.Text;
                lRecordData[5] = txtUnit.Text;
                try
                {
                    lRecordData[6] = cboLocation.SelectedValue.ToString();
                }
                catch
                {
                    lRecordData[6] = "";
                }
                lRecordData[7]  = cboLocation.Text;
                lRecordData[8]  = string.Format("{0:n}", decimal.Parse(txtSOQty.Text));
                lRecordData[9]  = string.Format("{0:n}", decimal.Parse(txtQtyOUT.Text));
                lRecordData[10] = string.Format("{0:n}", decimal.Parse(txtVariance.Text));
                lRecordData[11] = GlobalFunctions.replaceChar(txtRemarks.Text);

                object[] _params = { lRecordData };
                if (lOperator == "Add")
                {
                    lRecordData[12] = "Add";
                    ParentList.GetType().GetMethod("addData").Invoke(ParentList, _params);
                    MessageBoxUI _mbStatus = new MessageBoxUI("Successfully added!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                    _mbStatus.ShowDialog();
                    clear();
                }
                else if (lOperator == "Edit")
                {
                    lRecordData[12] = "Edit";
                    ParentList.GetType().GetMethod("updateData").Invoke(ParentList, _params);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 5
0
        private void StockWithdrawalDetailUI_Load(object sender, EventArgs e)
        {
            try
            {
                this.BackColor = Color.FromArgb(int.Parse(GlobalVariables.FormBackColor));

                try
                {
                    cboCustomer.DataSource    = loCustomer.getAllData("ViewAll", "", "");
                    cboCustomer.DisplayMember = "Name";
                    cboCustomer.ValueMember   = "Id";
                    cboCustomer.SelectedIndex = -1;
                }
                catch { }

                if (lOperation == GlobalVariables.Operation.Edit)
                {
                    foreach (DataRow _dr in loInventory.getAllData("", "", lInventoryId, "").Rows)
                    {
                        txtId.Text            = _dr["Id"].ToString();
                        dtpDate.Value         = GlobalFunctions.ConvertToDate(_dr["Date"].ToString());
                        txtReference.Text     = _dr["Reference"].ToString();
                        lSalesOrderId         = _dr["S.O. Id"].ToString();
                        cboCustomer.Text      = _dr["Customer"].ToString();
                        cboSalesOrder.Text    = _dr["S.O. Id"].ToString();
                        txtTotalSOQty.Text    = string.Format("{0:n}", decimal.Parse(_dr["Total S.O. Qty"].ToString()));
                        txtTotalQtyOut.Text   = string.Format("{0:n}", decimal.Parse(_dr["Total Qty Out"].ToString()));
                        txtTotalVariance.Text = string.Format("{0:n}", decimal.Parse(_dr["Total Variance"].ToString()));
                        txtRemarks.Text       = _dr["Remarks"].ToString();
                        foreach (DataRow _drDetails in loInventoryDetail.getInventoryDetails("", lInventoryId).Rows)
                        {
                            int i = dgvDetail.Rows.Add();
                            dgvDetail.Rows[i].Cells["Id"].Value               = _drDetails["Id"].ToString();
                            dgvDetail.Rows[i].Cells["SODetailId"].Value       = _drDetails["SODetailId"].ToString();
                            dgvDetail.Rows[i].Cells["StockId"].Value          = _drDetails["StockId"].ToString();
                            dgvDetail.Rows[i].Cells["StockCode"].Value        = _drDetails["Stock Code"].ToString();
                            dgvDetail.Rows[i].Cells["StockDescription"].Value = _drDetails["Stock Description"].ToString();
                            dgvDetail.Rows[i].Cells["Unit"].Value             = _drDetails["Unit"].ToString();
                            dgvDetail.Rows[i].Cells["LocationId"].Value       = _drDetails["LocationId"].ToString();
                            dgvDetail.Rows[i].Cells["Location"].Value         = _drDetails["Location"].ToString();
                            dgvDetail.Rows[i].Cells["SOQty"].Value            = string.Format("{0:n}", decimal.Parse(_drDetails["S.O. Qty"].ToString()));
                            dgvDetail.Rows[i].Cells["QtyOut"].Value           = string.Format("{0:n}", decimal.Parse(_drDetails["Qty Out"].ToString()));
                            dgvDetail.Rows[i].Cells["Variance"].Value         = string.Format("{0:n}", decimal.Parse(_drDetails["Variance"].ToString()));
                            dgvDetail.Rows[i].Cells["Remarks"].Value          = _drDetails["Remarks"].ToString();
                            dgvDetail.Rows[i].Cells["Status"].Value           = "Saved";
                        }
                        computeTotalQty();
                    }
                }
                else
                {
                    foreach (DataRow _dr in loCommon.getNextTabelSequenceId("Inventory").Rows)
                    {
                        txtId.Text = _dr[0].ToString();
                    }
                    cboCustomer.Focus();
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "StockWithdrawalDetailUI_Load");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 6
0
        private void MDIFrameWork_Load(object sender, EventArgs e)
        {
            try
            {
                this.Text        += " [" + GlobalVariables.CurrentConnection + "]";
                pnlMenu.BackColor = Color.FromArgb(int.Parse(GlobalVariables.SecondaryColor));
                getGlobalVariablesData();
                try
                {
                    byte[] hextobyte = GlobalFunctions.HexToBytes(GlobalVariables.ScreenSaverImage);
                    pctScreenSaver.BackgroundImage       = GlobalFunctions.ConvertByteArrayToImage(hextobyte);
                    pctScreenSaver.BackgroundImageLayout = ImageLayout.Stretch;
                }
                catch { }
                try
                {
                    byte[] hextobyteLogo = GlobalFunctions.HexToBytes(GlobalVariables.CompanyLogo);
                    pctLogo.BackgroundImage = GlobalFunctions.ConvertByteArrayToImage(hextobyteLogo);
                }
                catch { }
                try
                {
                    switch (GlobalVariables.TabAlignment)
                    {
                    case "Top":
                        tbcNSites_V.Alignment = TabAlignment.Top;
                        break;

                    case "Bottom":
                        tbcNSites_V.Alignment = TabAlignment.Bottom;
                        break;

                    case "Left":
                        tbcNSites_V.Alignment = TabAlignment.Left;
                        break;

                    case "Right":
                        tbcNSites_V.Alignment = TabAlignment.Right;
                        break;

                    default:
                        tbcNSites_V.Alignment = TabAlignment.Top;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                lblUsername.Text         = "Welcome!  " + GlobalVariables.Userfullname;
                lblDateTime.Text         = DateTime.Now.ToLongDateString();
                lblOwnerName.UseMnemonic = false;
                lblOwnerName.Text        = GlobalVariables.CompanyName;
                lblApplicationName.Text  = GlobalVariables.ApplicationName;
                if (GlobalVariables.Username != "admin" && GlobalVariables.Username != "technicalsupport")
                {
                    disabledMenuStrip();
                    enabledMenuStrip();
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "MDIFrameWork_Load");
                em.ShowDialog();
                Application.Exit();
            }
        }
        private void EmployeeDetailUI_Load(object sender, EventArgs e)
        {
            try
            {
                this.BackColor = Color.FromArgb(int.Parse(GlobalVariables.FormBackColor));
                try
                {
                    cboEmploymentType.DataSource    = loEmploymentType.getAllData("ViewAll", "", "");
                    cboEmploymentType.DisplayMember = "Description";
                    cboEmploymentType.ValueMember   = "Id";
                    cboEmploymentType.SelectedIndex = -1;
                }
                catch { }
                try
                {
                    cboDesignation.DataSource    = loDesignation.getAllData("ViewAll", "", "");
                    cboDesignation.DisplayMember = "Description";
                    cboDesignation.ValueMember   = "Id";
                    cboDesignation.SelectedIndex = -1;
                }
                catch { }
                try
                {
                    cboDepartment.DataSource    = loDepartment.getAllData("ViewAll", "", "");
                    cboDepartment.DisplayMember = "Description";
                    cboDepartment.ValueMember   = "Id";
                    cboDepartment.SelectedIndex = -1;
                }
                catch { }
                try
                {
                    cboImmediateSupervisor.DataSource    = loEmployee.getEmployeeNames();
                    cboImmediateSupervisor.DisplayMember = "Employee Name";
                    cboImmediateSupervisor.ValueMember   = "Id";
                    cboImmediateSupervisor.SelectedIndex = -1;
                }
                catch { }

                if (lOperation == GlobalVariables.Operation.Edit)
                {
                    foreach (DataRow _dr in loEmployee.getAllData("", lRecords[0].ToString(), "").Rows)
                    {
                        lId = _dr["Id"].ToString();
                        txtEmployeeNo.Text        = _dr["Employee No."].ToString();
                        txtLastname.Text          = _dr["Lastname"].ToString();
                        txtFirstname.Text         = _dr["Firstname"].ToString();
                        txtMiddlename.Text        = _dr["Middlename"].ToString();
                        chkActive.Checked         = _dr["Active"].ToString() == "Y" ? true : false;
                        txtBiometricsIdNo.Text    = _dr["Biometrics Id No."].ToString();
                        cboEmploymentType.Text    = _dr["Employment Type"].ToString();
                        cboDesignation.Text       = _dr["Designation"].ToString();
                        cboDepartment.Text        = _dr["Department"].ToString();
                        chkNoWorkSchedule.Checked = _dr["No Work Schedule"].ToString() == "Y" ? true : false;
                        cboWorkSchedule.Text      = _dr["Work Schedule"].ToString();
                        dtpBirthday.Value         = DateTime.Parse(_dr["Birthday"].ToString());
                        txtEmailAddress.Text      = _dr["Email Address"].ToString();
                        txtTIN.Text                   = _dr["TIN"].ToString();
                        chkTINDeducted.Checked        = _dr["TIN Deducted"].ToString() == "Y" ? true : false;
                        txtPhilHealthId.Text          = _dr["PhilHealth Id"].ToString();
                        chkPhilHealthDeducted.Checked = _dr["PhilHealth Deducted"].ToString() == "Y" ? true : false;
                        txtSSSId.Text                 = _dr["SSS Id"].ToString();
                        chkSSSDeducted.Checked        = _dr["SSS Deducted"].ToString() == "Y" ? true : false;
                        txtPagibigId.Text             = _dr["Pagibig Id"].ToString();
                        chkPagibigDeducted.Checked    = _dr["Pagibig Deducted"].ToString() == "Y" ? true : false;
                        txtPagibigEmployeeShare.Text  = string.Format("{0:n}", decimal.Parse(_dr["Pagibig(Employee Share)"].ToString()));
                        txtPagibigEmployerShare.Text  = string.Format("{0:n}", decimal.Parse(_dr["Pagibig(Employer Share)"].ToString()));
                        txtNoOfDependent.Text         = _dr["No. of Dependent"].ToString();
                        cboRateType.Text              = _dr["Rate Type"].ToString();
                        txtBasicPay.Text              = string.Format("{0:n}", decimal.Parse(_dr["Basic Pay"].ToString()));
                        cboImmediateSupervisor.Text   = _dr["Immediate Supervisor"].ToString();
                        txtRemarks.Text               = _dr["Remarks"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "EmployeeDetailUI_Load");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 8
0
        private void PurchaseOrderDetailUI_Load(object sender, EventArgs e)
        {
            try
            {
                this.BackColor = Color.FromArgb(int.Parse(GlobalVariables.FormBackColor));

                try
                {
                    cboSupplier.DataSource    = loSupplier.getAllData("ViewAll", "", "");
                    cboSupplier.DisplayMember = "Name";
                    cboSupplier.ValueMember   = "Id";
                    cboSupplier.SelectedIndex = -1;
                }
                catch { }

                try
                {
                    cboRequestedBy.DataSource    = loEmployee.getEmployeeNames();
                    cboRequestedBy.DisplayMember = "Employee Name";
                    cboRequestedBy.ValueMember   = "Id";
                    cboRequestedBy.SelectedIndex = -1;
                }
                catch { }

                if (lOperation == GlobalVariables.Operation.Edit)
                {
                    foreach (DataRow _dr in loPurchaseOrder.getAllData("", lPurchaseOrderId, "").Rows)
                    {
                        txtId.Text        = _dr["Id"].ToString();
                        dtpDate.Value     = GlobalFunctions.ConvertToDate(_dr["Date"].ToString());
                        txtReference.Text = _dr["Reference"].ToString();
                        try
                        {
                            cboSupplier.SelectedValue = _dr["SupplierId"].ToString();
                        }
                        catch
                        {
                            cboSupplier.Text = "";
                        }
                        cboPurchaseRequest.Text = _dr["P.R. Id"].ToString();
                        txtTerms.Text           = _dr["Terms"].ToString();
                        dtpDueDate.Value        = GlobalFunctions.ConvertToDate(_dr["Due Date"].ToString());
                        txtInstructions.Text    = _dr["Instructions"].ToString();
                        try
                        {
                            cboRequestedBy.SelectedValue = _dr["RequestedBy"].ToString();
                        }
                        catch
                        {
                            cboRequestedBy.Text = "";
                        }
                        dtpDateNeeded.Value      = GlobalFunctions.ConvertToDate(_dr["Date Needed"].ToString());
                        lblTotalPOQty.Text       = string.Format("{0:n}", decimal.Parse(_dr["Total P.O. Qty"].ToString()));
                        lblTotalQtyIn.Text       = string.Format("{0:n}", decimal.Parse(_dr["Total Qty In"].ToString()));
                        lblTotalQtyVariance.Text = string.Format("{0:n}", decimal.Parse(_dr["Total Qty Variance"].ToString()));
                        txtTotalAmount.Text      = string.Format("{0:n}", decimal.Parse(_dr["Total Amount"].ToString()));
                        txtRemarks.Text          = _dr["Remarks"].ToString();

                        foreach (DataRow _drDetails in loPurchaseOrderDetail.getPurchaseOrderDetails("", lPurchaseOrderId).Rows)
                        {
                            int i = dgvDetailStockInventory.Rows.Add();
                            dgvDetailStockInventory.Rows[i].Cells["Id"].Value               = _drDetails["Id"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["StockId"].Value          = _drDetails["StockId"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["StockCode"].Value        = _drDetails["Stock Code"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["StockDescription"].Value = _drDetails["Stock Description"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["Unit"].Value             = _drDetails["Unit"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["LocationId"].Value       = _drDetails["LocationId"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["Location"].Value         = _drDetails["Location"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["POQty"].Value            = string.Format("{0:n}", decimal.Parse(_drDetails["P.O. Qty"].ToString()));
                            dgvDetailStockInventory.Rows[i].Cells["QtyIn"].Value            = string.Format("{0:n}", decimal.Parse(_drDetails["Qty In"].ToString()));
                            dgvDetailStockInventory.Rows[i].Cells["QtyVariance"].Value      = string.Format("{0:n}", decimal.Parse(_drDetails["Qty Variance"].ToString()));
                            dgvDetailStockInventory.Rows[i].Cells["UnitPrice"].Value        = string.Format("{0:n}", decimal.Parse(_drDetails["Unit Price"].ToString()));

                            dgvDetailStockInventory.Rows[i].Cells["DiscountId"].Value     = _drDetails["DiscountId"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["Discount"].Value       = _drDetails["Discount"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["DiscountAmount"].Value = string.Format("{0:n}", decimal.Parse(_drDetails["Discount Amount"].ToString()));

                            dgvDetailStockInventory.Rows[i].Cells["TotalPrice"].Value = string.Format("{0:n}", decimal.Parse(_drDetails["Total Price"].ToString()));
                            dgvDetailStockInventory.Rows[i].Cells["Remarks"].Value    = _drDetails["Remarks"].ToString();
                            dgvDetailStockInventory.Rows[i].Cells["Status"].Value     = "Saved";
                        }
                        computeTotalAmount();
                        cboSupplier.Enabled              = false;
                        cboPurchaseRequest.Enabled       = false;
                        btnLookUpPurchaseRequest.Enabled = false;
                    }
                }
                else
                {
                    foreach (DataRow _dr in loCommon.getNextTabelSequenceId("PurchaseOrder").Rows)
                    {
                        txtId.Text = _dr[0].ToString();
                    }
                    cboSupplier.Focus();
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "PurchaseOrderDetailUI_Load");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (decimal.Parse(lblTotalPOQty.Text) == 0)
                {
                    MessageBoxUI _mb1 = new MessageBoxUI("Totals of P.O. Qty must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb1.showDialog();
                    return;
                }
                string _SupplierId = "";
                string _Employee   = "";
                try
                {
                    _SupplierId = cboSupplier.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mb1 = new MessageBoxUI("You must select a Supplier!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb1.showDialog();
                    cboSupplier.Focus();
                    return;
                }
                try
                {
                    _Employee = cboRequestedBy.SelectedValue.ToString();
                }
                catch
                {
                    _Employee = "";
                }
                DialogResult _dr = new DialogResult();
                MessageBoxUI _mb = new MessageBoxUI("Continue saving this Purchase Order?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                _mb.ShowDialog();
                _dr = _mb.Operation;
                if (_dr == DialogResult.Yes)
                {
                    loPurchaseOrder.Id   = lPurchaseOrderId;
                    loPurchaseOrder.Date = dtpDate.Value;
                    try
                    {
                        loPurchaseOrder.PRId = cboPurchaseRequest.SelectedValue.ToString();
                    }
                    catch
                    {
                        loPurchaseOrder.PRId = "";
                    }

                    loPurchaseOrder.Reference  = GlobalFunctions.replaceChar(txtReference.Text);
                    loPurchaseOrder.SupplierId = _SupplierId;
                    try
                    {
                        loPurchaseOrder.Terms = int.Parse(txtTerms.Text);
                    }
                    catch
                    {
                        loPurchaseOrder.Terms = 0;
                    }
                    loPurchaseOrder.DueDate          = dtpDueDate.Value;
                    loPurchaseOrder.Instructions     = GlobalFunctions.replaceChar(txtInstructions.Text);
                    loPurchaseOrder.RequestedBy      = _Employee;
                    loPurchaseOrder.DateNeeded       = dtpDateNeeded.Value;
                    loPurchaseOrder.TotalPOQty       = decimal.Parse(lblTotalPOQty.Text);
                    loPurchaseOrder.TotalQtyIn       = decimal.Parse(lblTotalQtyIn.Text);
                    loPurchaseOrder.TotalQtyVariance = decimal.Parse(lblTotalQtyVariance.Text);
                    loPurchaseOrder.TotalAmount      = decimal.Parse(txtTotalAmount.Text);
                    loPurchaseOrder.Remarks          = GlobalFunctions.replaceChar(txtRemarks.Text);
                    loPurchaseOrder.UserId           = GlobalVariables.UserId;

                    string _PurchaseOrderId = loPurchaseOrder.save(lOperation);
                    if (_PurchaseOrderId != "")
                    {
                        for (int i = 0; i < dgvDetailStockInventory.Rows.Count; i++)
                        {
                            if (dgvDetailStockInventory.Rows[i].Cells["Status"].Value.ToString() == "Add")
                            {
                                try
                                {
                                    loPurchaseOrderDetail.DetailId = dgvDetailStockInventory.Rows[i].Cells["Id"].Value.ToString();
                                }
                                catch
                                {
                                    loPurchaseOrderDetail.DetailId = "";
                                }
                                try
                                {
                                    loPurchaseOrderDetail.PurchaseOrderId = _PurchaseOrderId;
                                    loPurchaseOrderDetail.StockId         = dgvDetailStockInventory.Rows[i].Cells["StockId"].Value.ToString();
                                    loPurchaseOrderDetail.LocationId      = dgvDetailStockInventory.Rows[i].Cells["LocationId"].Value.ToString();
                                    loPurchaseOrderDetail.POQty           = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["POQty"].Value.ToString());
                                    loPurchaseOrderDetail.QtyIn           = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyIn"].Value.ToString());
                                    loPurchaseOrderDetail.QtyVariance     = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyVariance"].Value.ToString());
                                    loPurchaseOrderDetail.UnitPrice       = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["UnitPrice"].Value.ToString());
                                    loPurchaseOrderDetail.DiscountId      = dgvDetailStockInventory.Rows[i].Cells["DiscountId"].Value.ToString();
                                    loPurchaseOrderDetail.DiscountAmount  = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["DiscountAmount"].Value.ToString());
                                    loPurchaseOrderDetail.TotalPrice      = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["TotalPrice"].Value.ToString());
                                    loPurchaseOrderDetail.Remarks         = dgvDetailStockInventory.Rows[i].Cells["Remarks"].Value.ToString();
                                    loPurchaseOrderDetail.UserId          = GlobalVariables.UserId;
                                    loPurchaseOrderDetail.save(GlobalVariables.Operation.Add);
                                }
                                catch { }
                            }
                            else if (dgvDetailStockInventory.Rows[i].Cells["Status"].Value.ToString() == "Edit")
                            {
                                try
                                {
                                    loPurchaseOrderDetail.DetailId = dgvDetailStockInventory.Rows[i].Cells["Id"].Value.ToString();
                                }
                                catch
                                {
                                    loPurchaseOrderDetail.DetailId = "";
                                }
                                loPurchaseOrderDetail.PurchaseOrderId = _PurchaseOrderId;
                                loPurchaseOrderDetail.StockId         = dgvDetailStockInventory.Rows[i].Cells["StockId"].Value.ToString();
                                loPurchaseOrderDetail.LocationId      = dgvDetailStockInventory.Rows[i].Cells["LocationId"].Value.ToString();
                                loPurchaseOrderDetail.POQty           = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["POQty"].Value.ToString());
                                loPurchaseOrderDetail.QtyIn           = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyIn"].Value.ToString());
                                loPurchaseOrderDetail.QtyVariance     = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyVariance"].Value.ToString());
                                loPurchaseOrderDetail.UnitPrice       = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["UnitPrice"].Value.ToString());
                                loPurchaseOrderDetail.DiscountId      = dgvDetailStockInventory.Rows[i].Cells["DiscountId"].Value.ToString();
                                loPurchaseOrderDetail.DiscountAmount  = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["DiscountAmount"].Value.ToString());
                                loPurchaseOrderDetail.TotalPrice      = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["TotalPrice"].Value.ToString());
                                loPurchaseOrderDetail.Remarks         = dgvDetailStockInventory.Rows[i].Cells["Remarks"].Value.ToString();
                                loPurchaseOrderDetail.UserId          = GlobalVariables.UserId;
                                loPurchaseOrderDetail.save(GlobalVariables.Operation.Edit);
                            }
                            else if (dgvDetailStockInventory.Rows[i].Cells["Status"].Value.ToString() == "Delete")
                            {
                                loPurchaseOrderDetail.remove(dgvDetailStockInventory.Rows[i].Cells[0].Value.ToString());
                            }
                        }
                        if (txtId.Text == _PurchaseOrderId)
                        {
                            MessageBoxUI _mb2 = new MessageBoxUI("Purchase Order has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                            _mb2.showDialog();
                        }
                        else
                        {
                            MessageBoxUI _mb2 = new MessageBoxUI("Purchase Order has been saved successfully! New Purchase Order ID. : " + _PurchaseOrderId, GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                            _mb2.showDialog();
                        }

                        //previewDetail(_PurchaseOrderId);

                        object[] _params = { };
                        ParentList.GetType().GetMethod("refresh").Invoke(ParentList, _params);
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmSalesOrder", "Cancel"))
                {
                    return;
                }
                
                foreach (DataRow _drStatus in loSalesOrder.getSalesOrderStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    if (_drStatus["Final"].ToString() == "N")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Sales Order must be FINALIZED to be cancelled!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    if (_drStatus["Cancel"].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Sales Order is already cancelled!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    if (_drStatus["Post"].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("You cannot cancel a POSTED Sales Order!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    /*
                    if (_drStatus[1].ToString() == GlobalVariables.Username || _drStatus[4].ToString() == GlobalVariables.Username)
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("You cannot CANCEL a Sales Order you preprared/finalized!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    */
                }
                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue cancelling this Sales Order record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        SalesCancelReasonUI loSalesCancelReason = new SalesCancelReasonUI();
                        loSalesCancelReason.ShowDialog();
                        if (loSalesCancelReason.lReason == "")
                        {
                            MessageBoxUI _mb1 = new MessageBoxUI("You must have a reason in cancelling entry!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mb1.ShowDialog();
                            return;
                        }
                        else
                        {
                            if (loSalesOrder.cancel(dgvList.CurrentRow.Cells[0].Value.ToString(), loSalesCancelReason.lReason))
                            {
                                foreach (DataRow _drSO in loJournalEntry.getJournalEntryBySOId(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                                {
                                    loJournalEntry.cancel(_drSO[0].ToString(), loSalesCancelReason.lReason);
                                }

                                MessageBoxUI _mb1 = new MessageBoxUI("Sales Order record has been successfully cancelled!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                                _mb1.ShowDialog();
                                refresh();
                            }
                            else
                            {

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnCancel_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnPost_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmSalesOrder", "Post"))
                {
                    return;
                }

                foreach (DataRow _drStatus in loSalesOrder.getSalesOrderStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    if (_drStatus["Final"].ToString() == "N")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Sales Order must be FINALIZED!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    else if (_drStatus["Cancel"].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("You cannot post a CANCELLED Sales Order!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    else if (_drStatus["Post"].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Sales Order is already POSTED!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    else if (decimal.Parse(_drStatus["TotalQtyOut"].ToString()) <= 0)
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Total Qty OUT must be greater than or equal to zero(0)!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    /*
                    if (_drStatus[4].ToString() == GlobalVariables.Username)
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("You cannot FINALIZE a Sales Order you preprared!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    */
                    /*
                    if (_drStatus["SWId"].ToString() == "")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Stocks Withdrawal must precedes finalization!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    */
                }

                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue posting this Sales Order record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        if (loSalesOrder.post(dgvList.CurrentRow.Cells[0].Value.ToString()))
                        {
                            foreach (DataRow _drSO in loSalesOrder.getAllData("", dgvList.CurrentRow.Cells[0].Value.ToString(), "").Rows)
                            {
                                insertJournalEntry(dgvList.CurrentRow.Cells[0].Value.ToString(), decimal.Parse(_drSO["Total Amount"].ToString()),
                                    _drSO["CustomerId"].ToString(), _drSO["Customer"].ToString(), "Sales from Sales Order (SOId:" + _drSO["Id"].ToString() + ").");
                            }
           
                            MessageBoxUI _mb1 = new MessageBoxUI("Sales Order record has been successfully posted!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                            _mb1.ShowDialog();
                            //previewSalesOrderDetail(dgvList.CurrentRow.Cells[0].Value.ToString());
                            //sendEmailToCreator();
                            refresh();
                        }
                        else
                        {

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnPost_Click");
                em.ShowDialog();
                return;
            }
        }
 private void dgvList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     try
     {
         if (this.dgvList.Columns[e.ColumnIndex].Name == "Id" || this.dgvList.Columns[e.ColumnIndex].Name == "Terms" ||
             this.dgvList.Columns[e.ColumnIndex].Name == "Reference" || this.dgvList.Columns[e.ColumnIndex].Name == "P.Q. Id")
         {
             if (e.Value != null)
             {
                 e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
             }
         }
         else if (this.dgvList.Columns[e.ColumnIndex].Name == "Total S.O. Qty" || this.dgvList.Columns[e.ColumnIndex].Name == "Total Amount" ||
             this.dgvList.Columns[e.ColumnIndex].Name == "Running Balance" || this.dgvList.Columns[e.ColumnIndex].Name == "Total Qty Out" ||
             this.dgvList.Columns[e.ColumnIndex].Name == "Total Qty Variance")
         {
             if (e.Value != null)
             {
                 e.Value = string.Format("{0:n}", decimal.Parse(e.Value.ToString()));
                 e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
             }
         }
         else if (this.dgvList.Columns[e.ColumnIndex].Name == "Final")
         {
             if (e.Value != null)
             {
                 e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                 if (e.Value.ToString() == "N")
                 {
                     e.CellStyle.BackColor = Color.Green;
                 }
             }
         }
         if (this.dgvList.Columns[e.ColumnIndex].Name == "Cancel")
         {
             if (e.Value != null)
             {
                 e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                 if (e.Value.ToString() == "Y")
                 {
                     e.CellStyle.BackColor = Color.Red;
                 }
             }
         }
         if (this.dgvList.Columns[e.ColumnIndex].Name == "Post")
         {
             if (e.Value != null)
             {
                 e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                 if (e.Value.ToString() == "N")
                 {
                     e.CellStyle.BackColor = Color.Blue;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "dgvList_CellFormatting");
         em.ShowDialog();
         return;
     }
 }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsm" + lType.Name, "Search"))
                {
                    return;
                }

                string _DisplayFields = "";
                string _WhereFields   = "";
                string _Alias         = "";

                switch (lType.Name)
                {
                case "Client":
                    _DisplayFields = "SELECT Id,Lastname,Firstname,Middlename,Nickname,CellphoneNo AS `Cellphone No.`, " +
                                     "DATE_FORMAT(Birthday,'%m-%d-%Y') AS `Date`, " +
                                     "SitioPurokStreet AS `Sitio/Purok/Street`,Barangay,TownCity AS `Town/City`, " +
                                     "Province,YearsOfStay AS `Years of Stay`,HomeType AS `Home Type`,Remarks " +
                                     "FROM `client` ";
                    _WhereFields = " AND `Status` = 'Active' ORDER BY Lastname,Firstname ASC;";
                    _Alias       = "";
                    break;

                case "Area":
                    _DisplayFields = "SELECT a.Id,a.Code,a.Description, " +
                                     "CONCAT(e.Firstname,' ',SUBSTRING(e.Middlename, 1, 1),'. ',e.Lastname) AS `Area Manager`,a.Remarks " +
                                     "FROM `area` a " +
                                     "LEFT JOIN employee e " +
                                     "ON a.AreaManager = e.Id ";
                    _WhereFields = " AND a.Status = 'Active' ORDER BY a.Description ASC;";
                    _Alias       = "";
                    break;

                case "Branch":
                    _DisplayFields = "SELECT b.Id,b.Code,b.Description,a.Description AS `Area`, " +
                                     "CONCAT(e.Firstname,' ',SUBSTRING(e.Middlename, 1, 1),'. ',e.Lastname) AS `Branch Manager`,b.Remarks " +
                                     "FROM branch b " +
                                     "LEFT JOIN `area` a " +
                                     "ON b.AreaId = a.Id " +
                                     "LEFT JOIN employee e " +
                                     "ON b.BranchManager = e.Id ";
                    _WhereFields = " AND b.Status = 'Active' ORDER BY b.Description ASC;";
                    _Alias       = "";
                    break;

                case "Zone":
                    _DisplayFields = "SELECT z.Id,z.Description,b.Description AS `Branch`,z.Remarks " +
                                     "FROM zone z " +
                                     "LEFT JOIN branch b " +
                                     "ON z.BranchId = b.Id ";
                    _WhereFields = " AND z.Status = 'Active' ORDER BY z.Description ASC;";
                    _Alias       = "";
                    break;

                case "Collector":
                    _DisplayFields = "SELECT c.Id,CONCAT(e.Firstname,' ',SUBSTRING(e.Middlename, 1, 1),'. ',e.Lastname) AS `Employee Name`, " +
                                     "b.Description AS Branch, c.Remarks " +
                                     "FROM collector c " +
                                     "LEFT JOIN employee e " +
                                     "ON c.EmployeeId = e.Id " +
                                     "LEFT JOIN branch b " +
                                     "ON c.BranchId = b.Id ";
                    _WhereFields = " AND c.Status = 'Active' ORDER BY e.Firstname ASC;";
                    _Alias       = "";
                    break;

                case "Product":
                    _DisplayFields = "SELECT Id,`Code`,Description,PaymentFrequency AS `Payment Frequency`, " +
                                     "Terms,InterestRate AS `Interest Rate`,ServiceFeeRate AS `Service Fee Rate`,Remarks " +
                                     "FROM product ";
                    _WhereFields = " AND `Status` = 'Active' ORDER BY Description ASC;";
                    _Alias       = "";
                    break;
                }
                loSearches.lAlias = _Alias;
                loSearches.ShowDialog();
                if (loSearches.lFromShow)
                {
                    ldtShow = loCommon.getDataFromSearch(_DisplayFields + loSearches.lQuery + _WhereFields);
                    GlobalFunctions.refreshGrid(ref dgvLists, ldtShow);
                    lFromRefresh = false;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSearch_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsm" + lType.Name, "Update"))
                {
                    return;
                }

                for (int i = 0; i < lCountCol; i++)
                {
                    lRecord[i] = dgvLists.CurrentRow.Cells[i].Value.ToString();
                }

                if (lRecord.Length > 0)
                {
                    if (lRecord[0].ToString() != "")
                    {
                        switch (lType.Name)
                        {
                        case "Client":
                            ClientDetailUI loClientDetail = new ClientDetailUI(lRecord);
                            loClientDetail.ParentList = this;
                            loClientDetail.ShowDialog();
                            break;

                        case "Area":
                            AreaDetailUI loAreaDetail = new AreaDetailUI(lRecord);
                            loAreaDetail.ParentList = this;
                            loAreaDetail.ShowDialog();
                            break;

                        case "Branch":
                            BranchDetailUI loBranchDetail = new BranchDetailUI(lRecord);
                            loBranchDetail.ParentList = this;
                            loBranchDetail.ShowDialog();
                            break;

                        case "Zone":
                            ZoneDetailUI loZoneDetail = new ZoneDetailUI(lRecord);
                            loZoneDetail.ParentList = this;
                            loZoneDetail.ShowDialog();
                            break;

                        case "Collector":
                            CollectorDetailUI loCollectorDetail = new CollectorDetailUI(lRecord);
                            loCollectorDetail.ParentList = this;
                            loCollectorDetail.ShowDialog();
                            break;

                        case "Product":
                            ProductDetailUI loProductDetail = new ProductDetailUI(lRecord);
                            loProductDetail.ParentList = this;
                            loProductDetail.ShowDialog();
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnUpdate_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 15
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            try
            {
                dgvDetail.Rows.Clear();
                dgvDetailPaymentReceipt.Rows.Clear();
                string _customerId = "";
                try
                {
                    _customerId = cboCustomer.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mb = new MessageBoxUI("You must select a Customer!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }

                //insert debit account
                string[] lRecordDebitData = new string[11];
                lRecordDebitData[0] = "";                             //detail id
                lRecordDebitData[1] = GlobalVariables.CRDebitAccount; //coa id
                lRecordDebitData[2] = "";
                lRecordDebitData[3] = "";
                foreach (DataRow _dr in loChartOfAccount.getAllData("", GlobalVariables.CRDebitAccount, "").Rows)
                {
                    lRecordDebitData[2] = _dr["Code"].ToString();                                     //coa code
                    lRecordDebitData[3] = _dr["Account Title"].ToString();                            //coa title
                }
                lRecordDebitData[4]  = string.Format("{0:n}", decimal.Parse(txtPaymentReceipt.Text)); //debit
                lRecordDebitData[5]  = "0.00";                                                        //credit
                lRecordDebitData[6]  = "Bank";                                                        //subsidiary
                lRecordDebitData[7]  = "";                                                            //subsidiary id/code
                lRecordDebitData[8]  = "";                                                            //subsidiary description
                lRecordDebitData[9]  = "";                                                            //remarks
                lRecordDebitData[10] = "Add";
                addData(lRecordDebitData);

                //insert credit account
                string[] lRecordCreditData = new string[11];
                lRecordCreditData[0] = "";                              //detail id
                lRecordCreditData[1] = GlobalVariables.CRCreditAccount; //coa id
                lRecordCreditData[2] = "";
                lRecordCreditData[3] = "";
                foreach (DataRow _dr in loChartOfAccount.getAllData("", GlobalVariables.CRCreditAccount, "").Rows)
                {
                    lRecordCreditData[2] = _dr["Code"].ToString();                                     //coa code
                    lRecordCreditData[3] = _dr["Account Title"].ToString();                            //coa title
                }
                lRecordCreditData[4]  = "0.00";                                                        //debit
                lRecordCreditData[5]  = string.Format("{0:n}", decimal.Parse(txtPaymentReceipt.Text)); //credit
                lRecordCreditData[6]  = "Customer";                                                    //subsidiary
                lRecordCreditData[7]  = _customerId;                                                   //subsidiary id/code
                lRecordCreditData[8]  = cboCustomer.Text;                                              //subsidiary description
                lRecordCreditData[9]  = "";                                                            //remarks
                lRecordCreditData[10] = "Add";
                addData(lRecordCreditData);

                //insert payment receive
                decimal _paymentbalance = decimal.Parse(txtPaymentReceipt.Text);

                foreach (DataRow _dr in loSalesOrder.getCashReceiptSOByCustomer(_customerId, "").Rows)
                {
                    if (_paymentbalance != 0)
                    {
                        if (decimal.Parse(_dr["Running Balance"].ToString()) == _paymentbalance)
                        {
                            string[] lRecordPaymentData = new string[7];
                            lRecordPaymentData[0] = "";                                                                       //detail
                            lRecordPaymentData[1] = _dr["Id"].ToString();                                                     // sales order id
                            lRecordPaymentData[2] = string.Format("{0:n}", decimal.Parse(_dr["Running Balance"].ToString())); // amount due
                            lRecordPaymentData[3] = string.Format("{0:n}", decimal.Parse(_dr["Running Balance"].ToString())); // payment amount
                            lRecordPaymentData[4] = "0.00";                                                                   // balance
                            lRecordPaymentData[5] = "";                                                                       // remarks
                            lRecordPaymentData[6] = "Add";
                            addDataReceipt(lRecordPaymentData, true);

                            _paymentbalance = decimal.Parse(_dr["Running Balance"].ToString()) - _paymentbalance;
                        }
                        else if (decimal.Parse(_dr["Running Balance"].ToString()) > _paymentbalance)
                        {
                            string[] lRecordPaymentData = new string[7];
                            lRecordPaymentData[0] = "";                                                                                         //detail
                            lRecordPaymentData[1] = _dr["Id"].ToString();                                                                       // sales order id
                            lRecordPaymentData[2] = string.Format("{0:n}", decimal.Parse(_dr["Running Balance"].ToString()));                   // amount due
                            lRecordPaymentData[3] = string.Format("{0:n}", _paymentbalance);                                                    // payment amount
                            lRecordPaymentData[4] = string.Format("{0:n}", decimal.Parse(_dr["Running Balance"].ToString()) - _paymentbalance); // balance
                            lRecordPaymentData[5] = "";                                                                                         // remarks
                            lRecordPaymentData[6] = "Add";
                            addDataReceipt(lRecordPaymentData, true);

                            _paymentbalance = 0;
                        }
                        else if (decimal.Parse(_dr["Running Balance"].ToString()) < _paymentbalance)
                        {
                            string[] lRecordPaymentData = new string[7];
                            lRecordPaymentData[0] = "";                                                                       //detail
                            lRecordPaymentData[1] = _dr["Id"].ToString();                                                     // sales order id
                            lRecordPaymentData[2] = string.Format("{0:n}", decimal.Parse(_dr["Running Balance"].ToString())); // amount due
                            lRecordPaymentData[3] = string.Format("{0:n}", decimal.Parse(_dr["Running Balance"].ToString())); // payment amount
                            lRecordPaymentData[4] = string.Format("{0:n}", 0);                                                // balance
                            lRecordPaymentData[5] = "";                                                                       // remarks
                            lRecordPaymentData[6] = "Add";
                            addDataReceipt(lRecordPaymentData, true);

                            _paymentbalance = _paymentbalance - decimal.Parse(_dr["Running Balance"].ToString());
                        }
                    }
                }
                if (_paymentbalance > 0)
                {
                    MessageBoxUI _mb = new MessageBoxUI("OVER PAYMENT! " + string.Format("{0:n}", _paymentbalance), GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnProcess_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvDetailList.Rows.Count == 0)
                {
                    MessageBoxUI _mb1 = new MessageBoxUI("Record count must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb1.showDialog();
                    return;
                }
                string _BranchId = "0";
                try
                {
                    _BranchId = cboBranch.SelectedValue.ToString();
                }
                catch
                {
                    _BranchId = "0";
                }
                if (_BranchId == "0")
                {
                    MessageBoxUI _mb1 = new MessageBoxUI("You must select a branch!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb1.showDialog();
                    return;
                }

                DialogResult _dr = new DialogResult();
                MessageBoxUI _mb = new MessageBoxUI("Continue closing this End of Day?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                _mb.ShowDialog();
                _dr = _mb.Operation;
                if (_dr == DialogResult.Yes)
                {
                    loLoanEndOfDay.Id                  = "";
                    loLoanEndOfDay.Date                = dtpDate.Value;
                    loLoanEndOfDay.BranchId            = _BranchId;
                    loLoanEndOfDay.TotalAmountDue      = decimal.Parse(txtTotalAmountDue.Text);
                    loLoanEndOfDay.TotalRunningBalance = decimal.Parse(txtTotalRunningBalance.Text);
                    loLoanEndOfDay.TotalCollection     = decimal.Parse(txtTotalCollection.Text);
                    loLoanEndOfDay.TotalVariance       = decimal.Parse(txtTotalVariance.Text);
                    loLoanEndOfDay.TotalLoanRelease    = decimal.Parse(txtTotalLoanRelease.Text);
                    loLoanEndOfDay.TotalServiceFee     = decimal.Parse(txtTotalServiceFee.Text);
                    loLoanEndOfDay.EndedBy             = GlobalVariables.UserId;
                    loLoanEndOfDay.Remarks             = GlobalFunctions.replaceChar(txtRemarks.Text);
                    loLoanEndOfDay.UserId              = GlobalVariables.UserId;

                    try
                    {
                        string _LoanEODId = loLoanEndOfDay.save(lOperation);
                        if (_LoanEODId != "")
                        {
                            for (int i = 0; i < dgvDetailList.Rows.Count; i++)
                            {
                                try
                                {
                                    loLoanEndOfDayDetail.DetailId            = "";
                                    loLoanEndOfDayDetail.LoanEndOfDayId      = _LoanEODId;
                                    loLoanEndOfDayDetail.CollectorId         = dgvDetailList.Rows[i].Cells["CollectorId"].Value.ToString();
                                    loLoanEndOfDayDetail.TotalAmountDue      = decimal.Parse(dgvDetailList.Rows[i].Cells["TotalAmountDue"].Value.ToString());
                                    loLoanEndOfDayDetail.TotalRunningBalance = decimal.Parse(dgvDetailList.Rows[i].Cells["TotalRunningBalance"].Value.ToString());
                                    loLoanEndOfDayDetail.TotalCollection     = decimal.Parse(dgvDetailList.Rows[i].Cells["TotalCollection"].Value.ToString());
                                    loLoanEndOfDayDetail.TotalVariance       = decimal.Parse(dgvDetailList.Rows[i].Cells["TotalVariance"].Value.ToString());
                                    loLoanEndOfDayDetail.TotalLoanRelease    = decimal.Parse(dgvDetailList.Rows[i].Cells["TotalLoanRelease"].Value.ToString());
                                    loLoanEndOfDayDetail.TotalServiceFee     = decimal.Parse(dgvDetailList.Rows[i].Cells["TotalServiceFee"].Value.ToString());

                                    string _remarks = "";
                                    try
                                    {
                                        _remarks = dgvDetailList.Rows[i].Cells["Remarks"].Value.ToString();
                                    }
                                    catch
                                    {
                                        _remarks = "";
                                    }
                                    loLoanEndOfDayDetail.Remarks = _remarks;
                                    loLoanEndOfDayDetail.UserId  = GlobalVariables.UserId;
                                    loLoanEndOfDayDetail.save(GlobalVariables.Operation.Add);
                                }
                                catch { }
                            }
                            //update list
                            foreach (DataRow _drList in loLoanApplicationDetail.getEODLoanApplicationDetailList(dtpDate.Value, _BranchId).Rows)
                            {
                                loLoanApplicationDetail.updateEODLoanTransactionDetail(_drList[0].ToString(), _LoanEODId);
                            }

                            #region "Insert to Accounting"

                            string _financialYear = "", _journalEntryId = "";
                            try
                            {
                                foreach (DataRow _drAccounting in loCommon.getCurrentFinancialYear().Rows)
                                {
                                    _financialYear = _drAccounting[0].ToString();
                                }
                                //insert Collections
                                _journalEntryId = loCommon.insertJournalEntryFromOutside(_financialYear, "GJ", "JV", "", dtpDate.Value, "Lending Collection",
                                                                                         0, 0, "", "", "", GlobalVariables.UserId, "");
                                loCommon.insertJournalEntryDetailFromOutside(_journalEntryId, GlobalVariables.CollectionsDebit, decimal.Parse(txtTotalCollection.Text), 0, "", "", "", "", GlobalVariables.UserId);
                                loCommon.insertJournalEntryDetailFromOutside(_journalEntryId, GlobalVariables.CollectionsCredit, 0, decimal.Parse(txtTotalCollection.Text), "", "", "", "", GlobalVariables.UserId);

                                //insert Releases
                                _journalEntryId = loCommon.insertJournalEntryFromOutside(_financialYear, "GJ", "JV", "", dtpDate.Value, "Lending Releases",
                                                                                         0, 0, "", "", "", GlobalVariables.UserId, "");
                                loCommon.insertJournalEntryDetailFromOutside(_journalEntryId, GlobalVariables.ReleasesDebit, decimal.Parse(txtTotalLoanRelease.Text), 0, "", "", "", "", GlobalVariables.UserId);
                                loCommon.insertJournalEntryDetailFromOutside(_journalEntryId, GlobalVariables.ReleasesCredit, 0, decimal.Parse(txtTotalLoanRelease.Text), "", "", "", "", GlobalVariables.UserId);

                                //insert Service Fees
                                _journalEntryId = loCommon.insertJournalEntryFromOutside(_financialYear, "GJ", "JV", "", dtpDate.Value, "Lending Service Fees",
                                                                                         0, 0, "", "", "", GlobalVariables.UserId, "");
                                loCommon.insertJournalEntryDetailFromOutside(_journalEntryId, GlobalVariables.ServiceFeesDebit, decimal.Parse(txtTotalServiceFee.Text), 0, "", "", "", "", GlobalVariables.UserId);
                                loCommon.insertJournalEntryDetailFromOutside(_journalEntryId, GlobalVariables.ServiceFeesCredit, 0, decimal.Parse(txtTotalServiceFee.Text), "", "", "", "", GlobalVariables.UserId);
                            }
                            catch { }

                            #endregion

                            MessageBoxUI _mb2 = new MessageBoxUI("End of Day has been closed successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                            _mb2.showDialog();

                            object[] _params = { _BranchId };
                            ParentList.GetType().GetMethod("refresh").Invoke(ParentList, _params);
                            this.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("Unclosed quotation mark after the character string"))
                        {
                            MessageBoxUI _mb3 = new MessageBoxUI("Do not use this character( ' ).", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mb3.showDialog();
                            return;
                        }
                        else
                        {
                            MessageBoxUI _mb3 = new MessageBoxUI(ex.Message, GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mb3.showDialog();
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 17
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmSalesInventory", "Preview"))
                {
                    return;
                }

                try
                {
                    DataTable _dtByDate = loPOSTransactionDetail.getSalesInventory(dtpFromDate.Value, dtpToDate.Value);
                    if (_dtByDate.Rows.Count > 0)
                    {
                        loSalesInventoryRpt.SetDataSource(GlobalVariables.DTCompanyLogo);
                        loSalesInventoryRpt.Database.Tables[1].SetDataSource(_dtByDate);
                        loSalesInventoryRpt.SetParameterValue("CompanyName", GlobalVariables.CompanyName);
                        loSalesInventoryRpt.SetParameterValue("CompanyAddress", GlobalVariables.CompanyAddress);
                        loSalesInventoryRpt.SetParameterValue("CompanyContactNumber", GlobalVariables.ContactNumber);
                        loSalesInventoryRpt.SetParameterValue("Username", GlobalVariables.Userfullname);
                        loSalesInventoryRpt.SetParameterValue("DateFrom", string.Format("{0:MM-dd-yyyy}", dtpFromDate.Value));
                        loSalesInventoryRpt.SetParameterValue("DateTo", string.Format("{0:MM-dd-yyyy}", dtpToDate.Value));
                        loSalesInventoryRpt.SetParameterValue("Title", "Sales Inventory - By Date");
                        loSalesInventoryRpt.SetParameterValue("SubTitle", "Sales Inventory - By Date");
                        crvByDate.ReportSource = loSalesInventoryRpt;
                    }

                    DataTable _dtBy = loPOSTransactionDetail.getSalesInventoryBy(dtpFromDate.Value, dtpToDate.Value);

                    if (_dtBy.Rows.Count > 0)
                    {
                        loSalesInventoryByCustomerRpt.SetDataSource(GlobalVariables.DTCompanyLogo);
                        loSalesInventoryByCustomerRpt.Database.Tables[1].SetDataSource(_dtBy);
                        loSalesInventoryByCustomerRpt.SetParameterValue("CompanyName", GlobalVariables.CompanyName);
                        loSalesInventoryByCustomerRpt.SetParameterValue("CompanyAddress", GlobalVariables.CompanyAddress);
                        loSalesInventoryByCustomerRpt.SetParameterValue("CompanyContactNumber", GlobalVariables.ContactNumber);
                        loSalesInventoryByCustomerRpt.SetParameterValue("Username", GlobalVariables.Userfullname);
                        loSalesInventoryByCustomerRpt.SetParameterValue("DateFrom", string.Format("{0:MM-dd-yyyy}", dtpFromDate.Value));
                        loSalesInventoryByCustomerRpt.SetParameterValue("DateTo", string.Format("{0:MM-dd-yyyy}", dtpToDate.Value));
                        loSalesInventoryByCustomerRpt.SetParameterValue("Title", "Sales Inventory - By Customer");
                        loSalesInventoryByCustomerRpt.SetParameterValue("SubTitle", "Sales Inventory - By Customer");
                        crvByCustomer.ReportSource = loSalesInventoryByCustomerRpt;
                    }

                    if (_dtBy.Rows.Count > 0)
                    {
                        loSalesInventoryByCategoryRpt.SetDataSource(GlobalVariables.DTCompanyLogo);
                        loSalesInventoryByCategoryRpt.Database.Tables[1].SetDataSource(_dtBy);
                        loSalesInventoryByCategoryRpt.SetParameterValue("CompanyName", GlobalVariables.CompanyName);
                        loSalesInventoryByCategoryRpt.SetParameterValue("CompanyAddress", GlobalVariables.CompanyAddress);
                        loSalesInventoryByCategoryRpt.SetParameterValue("CompanyContactNumber", GlobalVariables.ContactNumber);
                        loSalesInventoryByCategoryRpt.SetParameterValue("Username", GlobalVariables.Userfullname);
                        loSalesInventoryByCategoryRpt.SetParameterValue("DateFrom", string.Format("{0:MM-dd-yyyy}", dtpFromDate.Value));
                        loSalesInventoryByCategoryRpt.SetParameterValue("DateTo", string.Format("{0:MM-dd-yyyy}", dtpToDate.Value));
                        loSalesInventoryByCategoryRpt.SetParameterValue("Title", "Sales Inventory - By Category");
                        loSalesInventoryByCategoryRpt.SetParameterValue("SubTitle", "Sales Inventory - By Category");
                        crvByCategory.ReportSource = loSalesInventoryByCategoryRpt;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnRefresh_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDebit.Text == "0.00" && txtCredit.Text == "0.00")
                {
                    MessageBoxUI _mbStatus = new MessageBoxUI("You must input an amount on Debit or Credit!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mbStatus.ShowDialog();
                    return;
                }

                lRecordData[0] = lDetailId;
                try
                {
                    lRecordData[1] = cboChartOfAccount.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mbStatus = new MessageBoxUI("You must select a correct Account Title!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mbStatus.ShowDialog();
                    cboChartOfAccount.Focus();
                    return;
                }
                lRecordData[2] = "";//chart of account code
                try
                {
                    foreach (DataRow _dr in loChartOfAccount.getAllData("", cboChartOfAccount.SelectedValue.ToString(), "").Rows)
                    {
                        lRecordData[2] = _dr["Code"].ToString();//chart of account code
                    }
                }
                catch
                {
                    lRecordData[2] = "";
                }
                lRecordData[3] = cboChartOfAccount.Text;
                lRecordData[4] = string.Format("{0:n}", decimal.Parse(txtDebit.Text));
                lRecordData[5] = string.Format("{0:n}", decimal.Parse(txtCredit.Text));
                lRecordData[6] = lblSubsidiary.Text;
                if (lblSubsidiary.Text != "")
                {
                    try
                    {
                        lRecordData[7] = cboSubsidiary.SelectedValue.ToString();
                        lRecordData[8] = cboSubsidiary.Text;
                    }
                    catch
                    {
                        if (cboSubsidiary.Items.Count > 0)
                        {
                            MessageBoxUI _mbError = new MessageBoxUI("You must select a correct " + lblSubsidiary.Text + "!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mbError.ShowDialog();
                            cboSubsidiary.Focus();
                            return;
                        }
                        else
                        {
                            lRecordData[7] = "";
                            lRecordData[8] = "";
                        }
                    }
                }
                else
                {
                    lRecordData[7] = "";
                    lRecordData[8] = "";
                }
                lRecordData[9] = GlobalFunctions.replaceChar(txtRemarks.Text);

                object[] _params = { lRecordData };
                if (lOperator == "Add")
                {
                    lRecordData[10] = "Add";
                    ParentList.GetType().GetMethod("addData").Invoke(ParentList, _params);
                    MessageBoxUI _mbStatus = new MessageBoxUI("Successfully added!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                    _mbStatus.ShowDialog();
                    clear();
                }
                else if (lOperator == "Edit")
                {
                    lRecordData[10] = "Edit";
                    ParentList.GetType().GetMethod("updateData").Invoke(ParentList, _params);
                    Close();
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 19
0
        private void btnFinalize_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmStockReceiving", "Finalize"))
                {
                    return;
                }
                string _POId = "";

                foreach (DataRow _drStatus in loInventory.getInventoryStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    _POId = _drStatus["POId"].ToString();

                    if (_drStatus["Final"].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Stock Inventory is already FINALIZED!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                }
                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue finalizing this Stock Inventory record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        if (loInventory.final(dgvList.CurrentRow.Cells[0].Value.ToString()))
                        {
                            //update PO Detail
                            foreach (DataRow _dr1 in loInventoryDetail.getInventoryDetails("", dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                            {
                                //update Qty
                                loPurchaseOrderDetail.updateQtyInPurchaseOrderDetail(_dr1["PODetailId"].ToString(), decimal.Parse(_dr1["Qty In"].ToString()), decimal.Parse(_dr1["Variance"].ToString()));
                                //updtae TotalPrice
                                decimal _totalPrice = 0;
                                foreach (DataRow _dr2 in loPurchaseOrderDetail.getPurchaseOrderDetail(_dr1["PODetailId"].ToString()).Rows)
                                {
                                    _totalPrice = decimal.Parse(_dr2["Qty In"].ToString()) * decimal.Parse(_dr2["Unit Price"].ToString());
                                    loPurchaseOrderDetail.updateTotalPricePurchaseOrderDetail(_dr1["PODetailId"].ToString(), _totalPrice);
                                }
                            }
                            //update PO Header Qty and Amount
                            decimal _totalQtyIn    = 0;
                            decimal _totalVariance = 0;
                            decimal _totalAmount   = 0;
                            foreach (DataRow _dr3 in loPurchaseOrderDetail.getPurchaseOrderDetails("", _POId).Rows)
                            {
                                _totalQtyIn    += decimal.Parse(_dr3["Qty In"].ToString());
                                _totalVariance += decimal.Parse(_dr3["Qty Variance"].ToString());
                                _totalAmount   += decimal.Parse(_dr3["Total Price"].ToString());
                            }

                            loPurchaseOrder.updatePOTotalAmount(_POId, _totalQtyIn, _totalVariance, _totalAmount);

                            MessageBoxUI _mb1 = new MessageBoxUI("Stock Inventory record has been successfully finalized!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                            _mb1.ShowDialog();
                            previewInventoryDetail(dgvList.CurrentRow.Cells[0].Value.ToString());
                            //sendEmailToCreator();
                            refresh("Stock Receiving");
                        }
                        else
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnFinalize_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 20
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                loUser.Id = lRecordData[0];

                if (txtUsername.Text != "")
                {
                    loUser.Username = GlobalFunctions.replaceChar(txtUsername.Text);
                }
                else
                {
                    MessageBoxUI ms = new MessageBoxUI("Username must have a value!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                    ms.showDialog();
                    txtUsername.Focus();
                    return;
                }
                loUser.Password = txtPassword.Text;
                try
                {
                    loUser.EmployeeId = cboEmployee.SelectedValue.ToString();
                }
                catch
                {
                    loUser.EmployeeId = "";
                }
                try
                {
                    loUser.UserGroupId = cboUserGroup.SelectedValue.ToString();
                }
                catch
                {
                    loUser.UserGroupId = "";
                }
                loUser.Remarks = txtRemarks.Text;
                loUser.UserId  = GlobalVariables.UserId;

                string _Id = loUser.saveUser(lOperation);
                if (_Id != "")
                {
                    MessageBoxUI _mb = new MessageBoxUI("User has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    lRecordData[0] = _Id;
                    lRecordData[1] = txtUsername.Text;
                    lRecordData[2] = cboEmployee.Text;
                    lRecordData[3] = cboUserGroup.Text;
                    lRecordData[4] = txtRemarks.Text;
                    object[] _params = { lRecordData };
                    if (lOperation == GlobalVariables.Operation.Edit)
                    {
                        ParentList.GetType().GetMethod("updateData").Invoke(ParentList, _params);
                        this.Close();
                    }
                    else
                    {
                        ParentList.GetType().GetMethod("addData").Invoke(ParentList, _params);
                        clear();
                    }
                }
                else
                {
                    MessageBoxUI _mb = new MessageBoxUI("Failure to save the record!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                loEmployee.Id             = lId;
                loEmployee.EmployeeNo     = GlobalFunctions.replaceChar(txtEmployeeNo.Text);
                loEmployee.Lastname       = GlobalFunctions.replaceChar(txtLastname.Text);
                loEmployee.Firstname      = GlobalFunctions.replaceChar(txtFirstname.Text);
                loEmployee.Middlename     = GlobalFunctions.replaceChar(txtMiddlename.Text);
                loEmployee.Active         = chkActive.Checked ? "Y" : "N";
                loEmployee.BiometricsIdNo = GlobalFunctions.replaceChar(txtBiometricsIdNo.Text);
                try
                {
                    loEmployee.EmploymentTypeId = cboEmploymentType.SelectedValue.ToString();
                }
                catch
                {
                    loEmployee.EmploymentTypeId = "0";
                }
                try
                {
                    loEmployee.DesignationId = cboDesignation.SelectedValue.ToString();
                }
                catch
                {
                    loEmployee.DesignationId = "0";
                }
                try
                {
                    loEmployee.DepartmentId = cboDepartment.SelectedValue.ToString();
                }
                catch
                {
                    loEmployee.DepartmentId = "0";
                }
                loEmployee.NoWorkSchedule = chkActive.Checked ? "Y" : "N";
                try
                {
                    loEmployee.WorkScheduleId = cboWorkSchedule.SelectedValue.ToString();
                }
                catch
                {
                    loEmployee.WorkScheduleId = "0";
                }
                loEmployee.Birthday             = dtpBirthday.Value;
                loEmployee.EmailAddress         = GlobalFunctions.replaceChar(txtEmailAddress.Text);
                loEmployee.TIN                  = GlobalFunctions.replaceChar(txtTIN.Text);
                loEmployee.TINDeducted          = chkTINDeducted.Checked ? "Y" : "N";
                loEmployee.PhilHealthId         = GlobalFunctions.replaceChar(txtPhilHealthId.Text);
                loEmployee.PhilHealthDeducted   = chkPhilHealthDeducted.Checked ? "Y" : "N";
                loEmployee.SSSId                = GlobalFunctions.replaceChar(txtSSSId.Text);
                loEmployee.SSSDeducted          = chkSSSDeducted.Checked ? "Y" : "N";
                loEmployee.PagibigId            = GlobalFunctions.replaceChar(txtPagibigId.Text);
                loEmployee.PagibigDeducted      = chkPagibigDeducted.Checked ? "Y" : "N";
                loEmployee.PagibigEmployeeShare = decimal.Parse(txtPagibigEmployeeShare.Text);
                loEmployee.PagibigEmployerShare = decimal.Parse(txtPagibigEmployerShare.Text);
                loEmployee.NoOfDependent        = int.Parse(txtNoOfDependent.Text);
                loEmployee.RateType             = cboRateType.Text;
                loEmployee.BasicPay             = decimal.Parse(txtBasicPay.Text);
                try
                {
                    loEmployee.ImmediateSupervisor = cboImmediateSupervisor.SelectedValue.ToString();
                }
                catch
                {
                    loEmployee.ImmediateSupervisor = "0";
                }
                loEmployee.Remarks = GlobalFunctions.replaceChar(txtRemarks.Text);
                loEmployee.UserId  = GlobalVariables.UserId;

                string _Id = loEmployee.save(lOperation);
                if (_Id != "")
                {
                    MessageBoxUI _mb = new MessageBoxUI("Employee has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    lRecords[0]  = _Id;
                    lRecords[1]  = txtEmployeeNo.Text;
                    lRecords[2]  = txtLastname.Text;
                    lRecords[3]  = txtFirstname.Text;
                    lRecords[4]  = txtMiddlename.Text;
                    lRecords[5]  = chkActive.Checked ? "Y" : "N";
                    lRecords[6]  = txtBiometricsIdNo.Text;
                    lRecords[7]  = cboEmploymentType.Text;
                    lRecords[8]  = cboDesignation.Text;
                    lRecords[9]  = cboDepartment.Text;
                    lRecords[10] = chkNoWorkSchedule.Checked ? "Y" : "N";
                    lRecords[11] = cboWorkSchedule.Text;
                    lRecords[12] = string.Format("{0:MM-dd-yyyy}", dtpBirthday.Value);
                    lRecords[13] = txtEmailAddress.Text;
                    lRecords[14] = txtTIN.Text;
                    lRecords[15] = chkTINDeducted.Checked ? "Y" : "N";
                    lRecords[16] = txtPhilHealthId.Text;
                    lRecords[17] = chkPhilHealthDeducted.Checked ? "Y" : "N";
                    lRecords[18] = txtSSSId.Text;
                    lRecords[19] = chkSSSDeducted.Checked ? "Y" : "N";
                    lRecords[20] = txtPagibigId.Text;
                    lRecords[21] = chkPagibigDeducted.Checked ? "Y" : "N";
                    lRecords[22] = decimal.Parse(txtPagibigEmployeeShare.Text).ToString();
                    lRecords[23] = decimal.Parse(txtPagibigEmployerShare.Text).ToString();
                    lRecords[24] = int.Parse(txtNoOfDependent.Text).ToString();
                    lRecords[25] = cboRateType.Text;
                    lRecords[26] = decimal.Parse(txtBasicPay.Text).ToString();
                    lRecords[27] = cboImmediateSupervisor.Text;
                    lRecords[28] = txtRemarks.Text;
                    object[] _params = { lRecords };
                    if (lOperation == GlobalVariables.Operation.Edit)
                    {
                        ParentList.GetType().GetMethod("updateData").Invoke(ParentList, _params);
                        this.Close();
                    }
                    else
                    {
                        ParentList.GetType().GetMethod("addData").Invoke(ParentList, _params);
                        clear();
                    }
                }
                else
                {
                    MessageBoxUI _mb = new MessageBoxUI("Failure to save the record!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsm" + lType.Name, "Search"))
                {
                    return;
                }

                string _DisplayFields = "";
                string _WhereFields   = "";
                string _Alias         = "";

                switch (lType.Name)
                {
                case "SalesDiscount":
                    _DisplayFields = "SELECT Id,`Code`,Description,`Type`,`Value`,Remarks " +
                                     "FROM salesdiscount ";
                    _WhereFields = " AND `Status` = 'Active' ORDER BY Description ASC;";
                    _Alias       = "";
                    break;

                case "ModeOfPayment":
                    _DisplayFields = "SELECT Id,`Code`,Description,`Default`,CashPayment AS ` Cash Payment`,Remarks " +
                                     "FROM modeofpayment ";
                    _WhereFields = " AND `Status` = 'Active' ORDER BY Description ASC;";
                    _Alias       = "";
                    break;

                case "SalesPerson":
                    _DisplayFields = "SELECT Id,`Name`,Address,ContactNo,EmailAddress AS `Email Address`,Remarks " +
                                     "FROM salesperson ";
                    _WhereFields = " AND `Status` = 'Active' ORDER BY `Name` ASC;";
                    _Alias       = "";
                    break;

                case "Cashier":
                    _DisplayFields = "SELECT c.Id,c.`Code`,c.`Name`,u.Username,c.Remarks " +
                                     "FROM cashier c " +
                                     "LEFT JOIN `user` u " +
                                     "ON c.UserId = u.Id ";
                    _WhereFields = " AND c.`Status` = 'Active' ORDER BY c.`Name` ASC;";
                    _Alias       = "";
                    break;
                }
                loSearches.lAlias = _Alias;
                loSearches.ShowDialog();
                if (loSearches.lFromShow)
                {
                    ldtShow = loCommon.getDataFromSearch(_DisplayFields + loSearches.lQuery + _WhereFields);
                    GlobalFunctions.refreshGrid(ref dgvLists, ldtShow);
                    lFromRefresh = false;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSearch_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                loBranch.Id          = lId;
                loBranch.Code        = txtCode.Text;
                loBranch.Description = GlobalFunctions.replaceChar(txtDescription.Text);
                try
                {
                    loBranch.AreaId = cboArea.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mb = new MessageBoxUI("You must select an Area!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    cboArea.Focus();
                    return;
                }
                try
                {
                    loBranch.BranchManager = cboBranchManager.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mb = new MessageBoxUI("You must select a Branch Manager!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    cboBranchManager.Focus();
                    return;
                }
                loBranch.Remarks = GlobalFunctions.replaceChar(txtRemarks.Text);
                loBranch.UserId  = GlobalVariables.UserId;

                string _Id = loBranch.save(lOperation);
                if (_Id != "")
                {
                    MessageBoxUI _mb = new MessageBoxUI("Branch has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    lRecords[0] = _Id;
                    lRecords[1] = txtCode.Text;
                    lRecords[2] = txtDescription.Text;
                    lRecords[3] = cboArea.Text;
                    lRecords[4] = cboBranchManager.Text;
                    lRecords[5] = txtRemarks.Text;
                    object[] _params = { lRecords };
                    if (lOperation == GlobalVariables.Operation.Edit)
                    {
                        ParentList.GetType().GetMethod("updateData").Invoke(ParentList, _params);
                        this.Close();
                    }
                    else
                    {
                        ParentList.GetType().GetMethod("addData").Invoke(ParentList, _params);
                        clear();
                    }
                }
                else
                {
                    MessageBoxUI _mb = new MessageBoxUI("Failure to save the record!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnPreview_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsm" + lType.Name, "Preview"))
                {
                    return;
                }
                if (dgvLists.Rows.Count != 0)
                {
                    switch (lType.Name)
                    {
                    case "SalesDiscount":
                        SalesDiscountRpt loSalesDiscountRpt = new SalesDiscountRpt();
                        loSalesDiscountRpt.SetDataSource(GlobalVariables.DTCompanyLogo);
                        loSalesDiscountRpt.Database.Tables[1].SetDataSource(ldtShow);
                        loSalesDiscountRpt.SetParameterValue("CompanyName", GlobalVariables.CompanyName);
                        loSalesDiscountRpt.SetParameterValue("CompanyAddress", GlobalVariables.CompanyAddress);
                        loSalesDiscountRpt.SetParameterValue("CompanyContactNumber", GlobalVariables.ContactNumber);
                        loSalesDiscountRpt.SetParameterValue("Username", GlobalVariables.Userfullname);
                        loSalesDiscountRpt.SetParameterValue("Title", "Sales Discount List");
                        loSalesDiscountRpt.SetParameterValue("SubTitle", "Sales Discount List");
                        try
                        {
                            if (loSearches.lAlias == "")
                            {
                                loSalesDiscountRpt.SetParameterValue("QueryString", loSearches.lQuery.Replace("WHERE ", ""));
                            }
                            else
                            {
                                loSalesDiscountRpt.SetParameterValue("QueryString", loSearches.lQuery.Replace("WHERE ", "").Replace(loSearches.lAlias, ""));
                            }
                        }
                        catch
                        {
                            loSalesDiscountRpt.SetParameterValue("QueryString", "");
                        }
                        loReportViewer.crystalReportViewer.ReportSource = loSalesDiscountRpt;
                        loReportViewer.ShowDialog();
                        break;

                    case "SalesPerson":
                        SalesPersonRpt loSalesPersonRpt = new SalesPersonRpt();
                        loSalesPersonRpt.SetDataSource(GlobalVariables.DTCompanyLogo);
                        loSalesPersonRpt.Database.Tables[1].SetDataSource(ldtShow);
                        loSalesPersonRpt.SetParameterValue("CompanyName", GlobalVariables.CompanyName);
                        loSalesPersonRpt.SetParameterValue("CompanyAddress", GlobalVariables.CompanyAddress);
                        loSalesPersonRpt.SetParameterValue("CompanyContactNumber", GlobalVariables.ContactNumber);
                        loSalesPersonRpt.SetParameterValue("Username", GlobalVariables.Userfullname);
                        loSalesPersonRpt.SetParameterValue("Title", "Sales Person List");
                        loSalesPersonRpt.SetParameterValue("SubTitle", "Sales Person List");
                        try
                        {
                            if (loSearches.lAlias == "")
                            {
                                loSalesPersonRpt.SetParameterValue("QueryString", loSearches.lQuery.Replace("WHERE ", ""));
                            }
                            else
                            {
                                loSalesPersonRpt.SetParameterValue("QueryString", loSearches.lQuery.Replace("WHERE ", "").Replace(loSearches.lAlias, ""));
                            }
                        }
                        catch
                        {
                            loSalesPersonRpt.SetParameterValue("QueryString", "");
                        }
                        loReportViewer.crystalReportViewer.ReportSource = loSalesPersonRpt;
                        loReportViewer.ShowDialog();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnPreview_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 25
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (decimal.Parse(txtTotalQtyOut.Text) == 0)
                {
                    MessageBoxUI _mb1 = new MessageBoxUI("Totals of Qty must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb1.showDialog();
                    return;
                }
                string _CustomerId = "";
                try
                {
                    _CustomerId = cboCustomer.SelectedValue.ToString();
                }
                catch
                {
                    _CustomerId = "";
                }
                DialogResult _dr = new DialogResult();
                MessageBoxUI _mb = new MessageBoxUI("Continue saving this Stock Withdrawal?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                _mb.ShowDialog();
                _dr = _mb.Operation;
                if (_dr == DialogResult.Yes)
                {
                    loInventory.Id   = lInventoryId;
                    loInventory.Date = dtpDate.Value;
                    loInventory.Type = "Stock Withdrawal";
                    loInventory.POId = "";
                    try
                    {
                        loInventory.SOId = cboSalesOrder.Text;
                    }
                    catch
                    {
                        loInventory.SOId = "";
                    }
                    loInventory.STInId         = "";
                    loInventory.STOutId        = "";
                    loInventory.Reference      = GlobalFunctions.replaceChar(txtReference.Text);
                    loInventory.CustomerId     = _CustomerId;
                    loInventory.SupplierId     = "0";
                    loInventory.TotalPOQty     = 0;
                    loInventory.TotalQtyIn     = 0;
                    loInventory.TotalSOQty     = decimal.Parse(txtTotalSOQty.Text);
                    loInventory.TotalQtyOut    = decimal.Parse(txtTotalQtyOut.Text);
                    loInventory.TotalVariance  = decimal.Parse(txtTotalVariance.Text);
                    loInventory.FromLocationId = "";
                    loInventory.ToLocationId   = "";
                    loInventory.Remarks        = GlobalFunctions.replaceChar(txtRemarks.Text);
                    loInventory.UserId         = GlobalVariables.UserId;

                    try
                    {
                        string _InventoryId = loInventory.save(lOperation);
                        if (_InventoryId != "")
                        {
                            for (int i = 0; i < dgvDetail.Rows.Count; i++)
                            {
                                if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Add")
                                {
                                    try
                                    {
                                        loInventoryDetail.DetailId = dgvDetail.Rows[i].Cells[0].Value.ToString();
                                    }
                                    catch
                                    {
                                        loInventoryDetail.DetailId = "";
                                    }
                                    try
                                    {
                                        loInventoryDetail.InventoryId = _InventoryId;
                                        loInventoryDetail.PODetailId  = "0";
                                        loInventoryDetail.SODetailId  = dgvDetail.Rows[i].Cells[1].Value.ToString();
                                        loInventoryDetail.StockId     = dgvDetail.Rows[i].Cells[2].Value.ToString();
                                        loInventoryDetail.LocationId  = dgvDetail.Rows[i].Cells[6].Value.ToString();
                                        loInventoryDetail.POQty       = 0;
                                        loInventoryDetail.QtyIn       = 0;
                                        loInventoryDetail.SOQty       = decimal.Parse(dgvDetail.Rows[i].Cells[8].Value.ToString());
                                        loInventoryDetail.QtyOut      = decimal.Parse(dgvDetail.Rows[i].Cells[9].Value.ToString());
                                        loInventoryDetail.Variance    = decimal.Parse(dgvDetail.Rows[i].Cells[10].Value.ToString());
                                        loInventoryDetail.Remarks     = dgvDetail.Rows[i].Cells[11].Value.ToString();
                                        loInventoryDetail.UserId      = GlobalVariables.UserId;
                                        loInventoryDetail.save(GlobalVariables.Operation.Add);
                                    }
                                    catch { }
                                }
                                else if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Edit")
                                {
                                    try
                                    {
                                        loInventoryDetail.DetailId = dgvDetail.Rows[i].Cells[0].Value.ToString();
                                    }
                                    catch
                                    {
                                        loInventoryDetail.DetailId = "";
                                    }
                                    try
                                    {
                                        loInventoryDetail.InventoryId = _InventoryId;
                                        loInventoryDetail.PODetailId  = "0";
                                        loInventoryDetail.SODetailId  = dgvDetail.Rows[i].Cells[1].Value.ToString();
                                        loInventoryDetail.StockId     = dgvDetail.Rows[i].Cells[2].Value.ToString();
                                        loInventoryDetail.LocationId  = dgvDetail.Rows[i].Cells[6].Value.ToString();
                                        loInventoryDetail.POQty       = 0;
                                        loInventoryDetail.QtyIn       = 0;
                                        loInventoryDetail.SOQty       = decimal.Parse(dgvDetail.Rows[i].Cells[8].Value.ToString());
                                        loInventoryDetail.QtyOut      = decimal.Parse(dgvDetail.Rows[i].Cells[9].Value.ToString());
                                        loInventoryDetail.Variance    = decimal.Parse(dgvDetail.Rows[i].Cells[10].Value.ToString());
                                        loInventoryDetail.Remarks     = dgvDetail.Rows[i].Cells[11].Value.ToString();
                                        loInventoryDetail.UserId      = GlobalVariables.UserId;
                                        loInventoryDetail.save(GlobalVariables.Operation.Edit);
                                    }
                                    catch { }
                                }
                                else if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Delete")
                                {
                                    loInventoryDetail.remove(dgvDetail.Rows[i].Cells[0].Value.ToString());
                                }
                            }
                            if (txtId.Text == _InventoryId)
                            {
                                MessageBoxUI _mb2 = new MessageBoxUI("Stock Withdrawal has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                                _mb2.showDialog();
                            }
                            else
                            {
                                MessageBoxUI _mb2 = new MessageBoxUI("Stock Withdrawal has been saved successfully! New Stock Withdrawal Id : " + _InventoryId, GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                                _mb2.showDialog();
                            }

                            //previewDetail(_InventoryId);

                            object[] _params = { "Stock Withdrawal" };
                            ParentList.GetType().GetMethod("refresh").Invoke(ParentList, _params);
                            this.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("Unclosed quotation mark after the character string"))
                        {
                            MessageBoxUI _mb3 = new MessageBoxUI("Do not use this character( ' ).", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mb3.showDialog();
                            return;
                        }
                        else
                        {
                            MessageBoxUI _mb3 = new MessageBoxUI(ex.Message, GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mb3.showDialog();
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 26
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvDetail.Rows.Count == 0)
                {
                    MessageBoxUI _mb = new MessageBoxUI("Journal Entry must a record!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
                if (dgvDetailPaymentReceipt.Rows.Count == 0)
                {
                    MessageBoxUI _mb = new MessageBoxUI("Payment Receipt must a record!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
                if (decimal.Parse(txtTotalDebit.Text) != decimal.Parse(txtTotalCredit.Text))
                {
                    MessageBoxUI _mb = new MessageBoxUI("Totals of Debit and Credit must be equal!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
                if (decimal.Parse(txtTotalDebit.Text) == 0 && decimal.Parse(txtTotalCredit.Text) == 0)
                {
                    MessageBoxUI _mb = new MessageBoxUI("Totals of Debit and Credit must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
                if (dtpDatePrepared.Value.Year != int.Parse(GlobalVariables.CurrentFinancialYear))
                {
                    MessageBoxUI _mb = new MessageBoxUI("Date Prepared must be within Current Financial Year!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }

                /*
                 * if (decimal.Parse(txtTotalPaymentAmount.Text) == 0)
                 * {
                 *  MessageBoxUI _mb1 = new MessageBoxUI("Totals Payment Amount must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                 *  _mb1.showDialog();
                 *  return;
                 * }
                 */
                //check if subsidiary has value
                for (int i = 0; i < dgvDetail.Rows.Count; i++)
                {
                    if (dgvDetail.Rows[i].Cells["Subsidiary"].Value.ToString() != "" && dgvDetail.Rows[i].Cells["SubsidiaryId"].Value.ToString() == "")
                    {
                        MessageBoxUI _mb1 = new MessageBoxUI("Subsidiary " + dgvDetail.Rows[i].Cells["Subsidiary"].Value.ToString() + " must have a value!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                        _mb1.showDialog();
                        return;
                    }
                }
                if (decimal.Parse(lblJournalEntryAmount.Text) != decimal.Parse(lblReceiptsAmount.Text))
                {
                    MessageBoxUI _mb1 = new MessageBoxUI("Totals of Amount is not equal!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb1.showDialog();
                    return;
                }
                loJournalEntry.JournalEntryId = lJournalEntryId;
                loJournalEntry.FinancialYear  = int.Parse(txtFinancialYear.Text);
                loJournalEntry.Journal        = "CRJ";
                loJournalEntry.Form           = "RV";
                loJournalEntry.VoucherNo      = "";
                loJournalEntry.DatePrepared   = dtpDatePrepared.Value;
                loJournalEntry.Explanation    = GlobalFunctions.replaceChar(txtExplanation.Text);
                loJournalEntry.TotalDebit     = decimal.Parse(txtTotalDebit.Text);
                loJournalEntry.TotalCredit    = decimal.Parse(txtTotalCredit.Text);
                loJournalEntry.Reference      = txtReference.Text;
                loJournalEntry.SupplierId     = "";
                try
                {
                    loJournalEntry.CustomerId = cboCustomer.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mb = new MessageBoxUI("Customer must have a value!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    cboCustomer.Focus();
                    return;
                }
                loJournalEntry.BegBal       = "N";
                loJournalEntry.Adjustment   = "N";
                loJournalEntry.ClosingEntry = "N";
                loJournalEntry.PreparedBy   = GlobalVariables.Username;
                loJournalEntry.Remarks      = GlobalFunctions.replaceChar(txtRemarks.Text);
                loJournalEntry.SOId         = "0";
                loJournalEntry.POId         = "0";
                loJournalEntry.UserId       = GlobalVariables.UserId;

                string _JournalEntryId = loJournalEntry.save(lOperation);
                if (_JournalEntryId != "")
                {
                    //insert journal entry detail
                    for (int i = 0; i < dgvDetail.Rows.Count; i++)
                    {
                        if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Add")
                        {
                            loJournalEntryDetail.DetailId              = dgvDetail.Rows[i].Cells["Id"].Value.ToString();
                            loJournalEntryDetail.JournalEntryId        = _JournalEntryId;
                            loJournalEntryDetail.AccountId             = dgvDetail.Rows[i].Cells["AccountId"].Value.ToString();
                            loJournalEntryDetail.Debit                 = decimal.Parse(dgvDetail.Rows[i].Cells["Debit"].Value.ToString());
                            loJournalEntryDetail.Credit                = decimal.Parse(dgvDetail.Rows[i].Cells["Credit"].Value.ToString());
                            loJournalEntryDetail.Subsidiary            = dgvDetail.Rows[i].Cells["Subsidiary"].Value.ToString();
                            loJournalEntryDetail.SubsidiaryId          = dgvDetail.Rows[i].Cells["SubsidiaryId"].Value.ToString();
                            loJournalEntryDetail.SubsidiaryDescription = dgvDetail.Rows[i].Cells["Description"].Value.ToString();
                            loJournalEntryDetail.Remarks               = dgvDetail.Rows[i].Cells["Remarks"].Value.ToString();
                            loJournalEntryDetail.UserId                = GlobalVariables.UserId;
                            loJournalEntryDetail.save(GlobalVariables.Operation.Add);
                        }
                        else if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Edit")
                        {
                            loJournalEntryDetail.DetailId              = dgvDetail.Rows[i].Cells["Id"].Value.ToString();
                            loJournalEntryDetail.JournalEntryId        = _JournalEntryId;
                            loJournalEntryDetail.AccountId             = dgvDetail.Rows[i].Cells["AccountId"].Value.ToString();
                            loJournalEntryDetail.Debit                 = decimal.Parse(dgvDetail.Rows[i].Cells["Debit"].Value.ToString());
                            loJournalEntryDetail.Credit                = decimal.Parse(dgvDetail.Rows[i].Cells["Credit"].Value.ToString());
                            loJournalEntryDetail.Subsidiary            = dgvDetail.Rows[i].Cells["Subsidiary"].Value.ToString();
                            loJournalEntryDetail.SubsidiaryId          = dgvDetail.Rows[i].Cells["SubsidiaryId"].Value.ToString();
                            loJournalEntryDetail.SubsidiaryDescription = dgvDetail.Rows[i].Cells["Description"].Value.ToString();
                            loJournalEntryDetail.Remarks               = dgvDetail.Rows[i].Cells["Remarks"].Value.ToString();
                            loJournalEntryDetail.UserId                = GlobalVariables.UserId;
                            loJournalEntryDetail.save(GlobalVariables.Operation.Edit);
                        }
                        else if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Delete")
                        {
                            loJournalEntryDetail.remove(dgvDetail.Rows[i].Cells[0].Value.ToString());
                        }
                    }
                    //insert payment receipt detail
                    for (int i = 0; i < dgvDetailPaymentReceipt.Rows.Count; i++)
                    {
                        if (dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptStatus"].Value.ToString() == "Add")
                        {
                            try
                            {
                                loCashReceiptDetail.DetailId = dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptId"].Value.ToString();
                            }
                            catch
                            {
                                loCashReceiptDetail.DetailId = "";
                            }
                            try
                            {
                                loCashReceiptDetail.JournalEntryId = _JournalEntryId;
                                loCashReceiptDetail.SalesOrderId   = dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptSOId"].Value.ToString();
                                loCashReceiptDetail.AmountDue      = decimal.Parse(dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptAmountDue"].Value.ToString());
                                loCashReceiptDetail.PaymentAmount  = decimal.Parse(dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptPaymentAmount"].Value.ToString());
                                loCashReceiptDetail.Balance        = decimal.Parse(dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptBalance"].Value.ToString());
                                loCashReceiptDetail.Remarks        = dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptRemarks"].Value.ToString();
                                loCashReceiptDetail.UserId         = GlobalVariables.UserId;
                                loCashReceiptDetail.save(GlobalVariables.Operation.Add);
                            }
                            catch { }
                        }
                        else if (dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptStatus"].Value.ToString() == "Edit")
                        {
                            try
                            {
                                loCashReceiptDetail.DetailId = dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptId"].Value.ToString();
                            }
                            catch
                            {
                                loCashReceiptDetail.DetailId = "";
                            }
                            loCashReceiptDetail.JournalEntryId = _JournalEntryId;
                            loCashReceiptDetail.SalesOrderId   = dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptSOId"].Value.ToString();
                            loCashReceiptDetail.AmountDue      = decimal.Parse(dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptAmountDue"].Value.ToString());
                            loCashReceiptDetail.PaymentAmount  = decimal.Parse(dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptPaymentAmount"].Value.ToString());
                            loCashReceiptDetail.Balance        = decimal.Parse(dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptBalance"].Value.ToString());
                            loCashReceiptDetail.Remarks        = dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptRemarks"].Value.ToString();
                            loCashReceiptDetail.UserId         = GlobalVariables.UserId;
                            loCashReceiptDetail.save(GlobalVariables.Operation.Edit);
                        }
                        else if (dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptStatus"].Value.ToString() == "Delete")
                        {
                            loCashReceiptDetail.remove(dgvDetailPaymentReceipt.Rows[i].Cells[0].Value.ToString());
                        }
                    }

                    MessageBoxUI _mb = new MessageBoxUI("Journal Entry has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    try
                    {
                        if (lOperation == GlobalVariables.Operation.Edit)
                        {
                            //sendEmailForPosting(_JournalEntryId, cboCompany.SelectedValue.ToString(), cboCompany.Text, string.Format("{0:MM-dd-yyyy}", dtpDatePrepared.Value), txtExplanation.Text, decimal.Parse(txtTotalDebit.Text), decimal.Parse(txtTotalCredit.Text), cboPayor.Text, GlobalVariables.Userfullname);
                        }
                    }
                    catch
                    {
                        MessageBoxUI _mb1 = new MessageBoxUI("Failure to send email", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                        _mb1.showDialog();
                    }
                    ParentList.GetType().GetMethod("refresh").Invoke(ParentList, null);

                    this.Close();
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmGeneralJournal", "Cancel"))
                {
                    return;
                }

                foreach (DataRow _drStatus in loJournalEntry.getJournalEntryStatus(dgvList.CurrentRow.Cells[0].Value.ToString()).Rows)
                {
                    if (_drStatus[0].ToString() == "N")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("You cannot cancel an UNPOSTED Journal Entry!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    if (_drStatus[2].ToString() == "Y")
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("Journal Entry is already cancelled!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                    if (_drStatus[1].ToString() == GlobalVariables.Username || _drStatus[4].ToString() == GlobalVariables.Username)
                    {
                        MessageBoxUI _mbStatus = new MessageBoxUI("You cannot CANCEL a Journal Entry you preprared/posted!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                        _mbStatus.ShowDialog();
                        return;
                    }
                }
                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue cancelling this Journal Entry record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        AccountingCancelReasonUI loReason = new AccountingCancelReasonUI();
                        loReason.ShowDialog();
                        if (loReason.lReason == "")
                        {
                            MessageBoxUI _mb1 = new MessageBoxUI("You must have a reason in cancelling entry!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mb1.ShowDialog();
                            return;
                        }
                        else
                        {
                            if (loJournalEntry.cancel(dgvList.CurrentRow.Cells[0].Value.ToString(), loReason.lReason))
                            {
                                MessageBoxUI _mb1 = new MessageBoxUI("Journal Entry record has been successfully cancelled!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                                _mb1.ShowDialog();
                                refresh();
                            }
                            else
                            {
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnCancel_Click");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 28
0
        private void CashReceiptVoucherUI_Load(object sender, EventArgs e)
        {
            try
            {
                this.BackColor = Color.FromArgb(int.Parse(GlobalVariables.FormBackColor));

                txtFinancialYear.Text = GlobalVariables.CurrentFinancialYear;

                cboCustomer.DataSource    = loCustomer.getAllData("ViewAll", "", "");
                cboCustomer.DisplayMember = "Name";
                cboCustomer.ValueMember   = "Id";
                cboCustomer.SelectedIndex = -1;

                if (lOperation == GlobalVariables.Operation.Edit)
                {
                    foreach (DataRow _dr in loJournalEntry.getAllData("", "", lJournalEntryId, "").Rows)
                    {
                        txtFinancialYear.Text = _dr["F.Y."].ToString();
                        dtpDatePrepared.Value = GlobalFunctions.ConvertToDate(_dr["Date Prepared"].ToString());
                        txtExplanation.Text   = _dr["Explanation"].ToString();
                        txtTotalDebit.Text    = string.Format("{0:n}", decimal.Parse(_dr["Total Debit"].ToString()));
                        txtTotalCredit.Text   = string.Format("{0:n}", decimal.Parse(_dr["Total Credit"].ToString()));
                        txtReference.Text     = _dr["Reference"].ToString();
                        try
                        {
                            cboCustomer.SelectedValue = _dr["CustomerId"].ToString();
                        }
                        catch
                        {
                            cboCustomer.SelectedIndex = -1;
                        }
                        txtRemarks.Text = _dr["Remarks"].ToString();
                        //get journal entry
                        foreach (DataRow _drDetails in loJournalEntryDetail.getJournalEntryDetails("", lJournalEntryId).Rows)
                        {
                            int i = dgvDetail.Rows.Add();
                            dgvDetail.Rows[i].Cells["Id"].Value           = _drDetails["Id"].ToString();
                            dgvDetail.Rows[i].Cells["AccountId"].Value    = _drDetails["AccountId"].ToString();
                            dgvDetail.Rows[i].Cells["AccountCode"].Value  = _drDetails["Account Code"].ToString();
                            dgvDetail.Rows[i].Cells["AccountTitle"].Value = _drDetails["Account Title"].ToString();
                            dgvDetail.Rows[i].Cells["Debit"].Value        = string.Format("{0:n}", decimal.Parse(_drDetails["Debit"].ToString()));
                            dgvDetail.Rows[i].Cells["Credit"].Value       = string.Format("{0:n}", decimal.Parse(_drDetails["Credit"].ToString()));
                            dgvDetail.Rows[i].Cells["Subsidiary"].Value   = _drDetails["Subsidiary"].ToString();
                            dgvDetail.Rows[i].Cells["SubsidiaryId"].Value = _drDetails["SubsidiaryId"].ToString();
                            dgvDetail.Rows[i].Cells["Description"].Value  = _drDetails["Subsidiary Description"].ToString();
                            dgvDetail.Rows[i].Cells["Remarks"].Value      = _drDetails["Remarks"].ToString();
                            dgvDetail.Rows[i].Cells["Status"].Value       = "Saved";
                        }
                        //get payment receipt
                        foreach (DataRow _drDetails in loCashReceiptDetail.getCashReceiptDetails(lJournalEntryId).Rows)
                        {
                            int i = dgvDetailPaymentReceipt.Rows.Add();
                            dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptId"].Value            = _drDetails["Id"].ToString();
                            dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptSOId"].Value          = _drDetails["S.O. Id"].ToString();
                            dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptAmountDue"].Value     = string.Format("{0:n}", decimal.Parse(_drDetails["Amount Due"].ToString()));
                            dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptPaymentAmount"].Value = string.Format("{0:n}", decimal.Parse(_drDetails["Payment Amount"].ToString()));
                            dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptBalance"].Value       = string.Format("{0:n}", decimal.Parse(_drDetails["Balance"].ToString()));
                            dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptRemarks"].Value       = _drDetails["Remarks"].ToString();
                            dgvDetailPaymentReceipt.Rows[i].Cells["ReceiptStatus"].Value        = "Saved";
                        }
                        computeTotal();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "CashReceiptVoucherUI_Load");
                em.ShowDialog();
                return;
            }
        }
Ejemplo n.º 29
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (decimal.Parse(txtTotalDebit.Text) != decimal.Parse(txtTotalCredit.Text))
                {
                    MessageBoxUI _mb = new MessageBoxUI("Totals of Debit and Credit must be equal!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
                if (decimal.Parse(txtTotalDebit.Text) == 0 && decimal.Parse(txtTotalCredit.Text) == 0)
                {
                    MessageBoxUI _mb = new MessageBoxUI("Totals of Debit and Credit must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
                if (dtpDatePrepared.Value.Year != int.Parse(GlobalVariables.CurrentFinancialYear))
                {
                    MessageBoxUI _mb = new MessageBoxUI("Date Prepared must be within Current Financial Year!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    return;
                }
                loJournalEntry.JournalEntryId = lJournalEntryId;
                loJournalEntry.FinancialYear  = int.Parse(txtFinancialYear.Text);
                loJournalEntry.Journal        = "SJ";
                loJournalEntry.Form           = "SV";
                loJournalEntry.VoucherNo      = "";
                loJournalEntry.DatePrepared   = dtpDatePrepared.Value;
                loJournalEntry.Explanation    = GlobalFunctions.replaceChar(txtExplanation.Text);
                loJournalEntry.TotalDebit     = decimal.Parse(txtTotalDebit.Text);
                loJournalEntry.TotalCredit    = decimal.Parse(txtTotalCredit.Text);
                loJournalEntry.Reference      = txtReference.Text;
                loJournalEntry.SupplierId     = "";
                try
                {
                    loJournalEntry.CustomerId = cboCustomer.SelectedValue.ToString();
                }
                catch
                {
                    MessageBoxUI _mb = new MessageBoxUI("Customer must have a value!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                    _mb.showDialog();
                    cboCustomer.Focus();
                    return;
                }
                loJournalEntry.BegBal       = "N";
                loJournalEntry.Adjustment   = "N";
                loJournalEntry.ClosingEntry = "N";
                loJournalEntry.PreparedBy   = GlobalVariables.Username;
                loJournalEntry.Remarks      = GlobalFunctions.replaceChar(txtRemarks.Text);
                loJournalEntry.SOId         = "0";
                loJournalEntry.POId         = "0";
                loJournalEntry.UserId       = GlobalVariables.UserId;

                try
                {
                    string _JournalEntryId = loJournalEntry.save(lOperation);
                    if (_JournalEntryId != "")
                    {
                        for (int i = 0; i < dgvAccountDetail.Rows.Count; i++)
                        {
                            if (dgvAccountDetail.Rows[i].Cells["Status"].Value.ToString() == "Add")
                            {
                                loJournalEntryDetail.DetailId              = dgvAccountDetail.Rows[i].Cells["Id"].Value.ToString();
                                loJournalEntryDetail.JournalEntryId        = _JournalEntryId;
                                loJournalEntryDetail.AccountId             = dgvAccountDetail.Rows[i].Cells["AccountId"].Value.ToString();
                                loJournalEntryDetail.Debit                 = decimal.Parse(dgvAccountDetail.Rows[i].Cells["Debit"].Value.ToString());
                                loJournalEntryDetail.Credit                = decimal.Parse(dgvAccountDetail.Rows[i].Cells["Credit"].Value.ToString());
                                loJournalEntryDetail.Subsidiary            = dgvAccountDetail.Rows[i].Cells["Subsidiary"].Value.ToString();
                                loJournalEntryDetail.SubsidiaryId          = dgvAccountDetail.Rows[i].Cells["SubsidiaryId"].Value.ToString();
                                loJournalEntryDetail.SubsidiaryDescription = dgvAccountDetail.Rows[i].Cells["Description"].Value.ToString();
                                loJournalEntryDetail.Remarks               = dgvAccountDetail.Rows[i].Cells["Remarks"].Value.ToString();
                                loJournalEntryDetail.UserId                = GlobalVariables.UserId;
                                loJournalEntryDetail.save(GlobalVariables.Operation.Add);
                            }
                            else if (dgvAccountDetail.Rows[i].Cells["Status"].Value.ToString() == "Edit")
                            {
                                loJournalEntryDetail.DetailId              = dgvAccountDetail.Rows[i].Cells["Id"].Value.ToString();
                                loJournalEntryDetail.JournalEntryId        = _JournalEntryId;
                                loJournalEntryDetail.AccountId             = dgvAccountDetail.Rows[i].Cells["AccountId"].Value.ToString();
                                loJournalEntryDetail.Debit                 = decimal.Parse(dgvAccountDetail.Rows[i].Cells["Debit"].Value.ToString());
                                loJournalEntryDetail.Credit                = decimal.Parse(dgvAccountDetail.Rows[i].Cells["Credit"].Value.ToString());
                                loJournalEntryDetail.Subsidiary            = dgvAccountDetail.Rows[i].Cells["Subsidiary"].Value.ToString();
                                loJournalEntryDetail.SubsidiaryId          = dgvAccountDetail.Rows[i].Cells["SubsidiaryId"].Value.ToString();
                                loJournalEntryDetail.SubsidiaryDescription = dgvAccountDetail.Rows[i].Cells["Description"].Value.ToString();
                                loJournalEntryDetail.Remarks               = dgvAccountDetail.Rows[i].Cells["Remarks"].Value.ToString();
                                loJournalEntryDetail.UserId                = GlobalVariables.UserId;
                                loJournalEntryDetail.save(GlobalVariables.Operation.Edit);
                            }
                            else if (dgvAccountDetail.Rows[i].Cells["Status"].Value.ToString() == "Delete")
                            {
                                loJournalEntryDetail.remove(dgvAccountDetail.Rows[i].Cells[0].Value.ToString());
                            }
                        }

                        MessageBoxUI _mb = new MessageBoxUI("Journal Entry has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK);
                        _mb.showDialog();
                        try
                        {
                            if (lOperation == GlobalVariables.Operation.Edit)
                            {
                                //sendEmailForPosting(_JournalEntryId, cboCompany.SelectedValue.ToString(), cboCompany.Text, string.Format("{0:MM-dd-yyyy}", dtpDatePrepared.Value), txtExplanation.Text, decimal.Parse(txtTotalDebit.Text), decimal.Parse(txtTotalCredit.Text), GlobalVariables.Userfullname);
                            }
                        }
                        catch
                        {
                            MessageBoxUI _mb1 = new MessageBoxUI("Failure to send email", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            _mb1.showDialog();
                        }
                        ParentList.GetType().GetMethod("refresh").Invoke(ParentList, null);

                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Unclosed quotation mark after the character string"))
                    {
                        MessageBoxUI _mb = new MessageBoxUI("Do not use this character( ' ).", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                        _mb.showDialog();
                        return;
                    }
                    else
                    {
                        MessageBoxUI _mb = new MessageBoxUI(ex.Message, GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                        _mb.showDialog();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click");
                em.ShowDialog();
                return;
            }
        }
        private void btnPost_Click(object sender, EventArgs e)
        {
            try
            {
                if (!GlobalFunctions.checkRights("tsmLoanApplication", "Post"))
                {
                    return;
                }
                string    _LoanApplicationId = dgvList.CurrentRow.Cells[0].Value.ToString();
                DataTable _dt = loLoanApplication.getLoanApplicationStatus(_LoanApplicationId);
                if (_dt.Rows.Count > 0)
                {
                    foreach (DataRow _drStatus in _dt.Rows)
                    {
                        if (_drStatus[0].ToString() == "In Process")
                        {
                            MessageBoxUI _mbStatus = new MessageBoxUI("You cannot post an IN PROCESS application!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                            _mbStatus.ShowDialog();
                            return;
                        }
                        else if (_drStatus[0].ToString() == "Cancelled")
                        {
                            MessageBoxUI _mbStatus = new MessageBoxUI("You cannot post a CANCELLED application!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                            _mbStatus.ShowDialog();
                            return;
                        }
                        else if (_drStatus[0].ToString() == "Posted")
                        {
                            MessageBoxUI _mbStatus = new MessageBoxUI("Loan application is already POSTED!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                            _mbStatus.ShowDialog();
                            return;
                        }
                    }
                }
                else
                {
                    MessageBoxUI _mbStatus = new MessageBoxUI("Loan Application Id does not exist!", GlobalVariables.Icons.Warning, GlobalVariables.Buttons.OK);
                    _mbStatus.ShowDialog();
                    return;
                }

                if (dgvList.Rows.Count > 0)
                {
                    DialogResult _dr = new DialogResult();
                    MessageBoxUI _mb = new MessageBoxUI("Are sure you want to continue posting this Loan Application record?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo);
                    _mb.ShowDialog();
                    _dr = _mb.Operation;
                    if (_dr == DialogResult.Yes)
                    {
                        try
                        {
                            if (loLoanApplication.post(_LoanApplicationId))
                            {
                                //create loan application detail
                                foreach (DataRow _drHeader in loLoanApplication.getAllData("", _LoanApplicationId, "").Rows)
                                {
                                    string   _PaymentFrequency       = _drHeader["Payment Frequency"].ToString();
                                    int      _Terms                  = int.Parse(_drHeader["Terms"].ToString());
                                    DateTime _StartDate              = DateTime.Parse(_drHeader["Start Date"].ToString());
                                    DateTime _MaturityDate           = DateTime.Parse(_drHeader["Maturity Date"].ToString());
                                    decimal  _TotalAmountDue         = decimal.Parse(_drHeader["Total Amount Due"].ToString());
                                    decimal  _InstallmentAmountDue   = decimal.Parse(_drHeader["Installment Amount Due"].ToString());
                                    decimal  _OriginalTotalAmountDue = decimal.Parse(_drHeader["Total Amount Due"].ToString());

                                    loLoanApplicationDetail.DetailId          = "";
                                    loLoanApplicationDetail.LoanApplicationId = _LoanApplicationId;
                                    loLoanApplicationDetail.SeqNo             = 0;
                                    loLoanApplicationDetail.Date              = _StartDate;
                                    loLoanApplicationDetail.AmountDue         = _TotalAmountDue;
                                    loLoanApplicationDetail.InstallmentAmount = _InstallmentAmountDue;
                                    loLoanApplicationDetail.PaymentAmount     = 0;
                                    loLoanApplicationDetail.RunningBalance    = _OriginalTotalAmountDue;
                                    loLoanApplicationDetail.NewBalance        = 0;
                                    loLoanApplicationDetail.Variance          = 0;
                                    loLoanApplicationDetail.PastDueReason     = "";
                                    loLoanApplicationDetail.Remarks           = "";
                                    loLoanApplicationDetail.UserId            = GlobalVariables.UserId;
                                    loLoanApplicationDetail.save(GlobalVariables.Operation.Add);

                                    int i = 1;
                                    for (DateTime _startDate = _StartDate.AddDays(1); _startDate <= _MaturityDate;)
                                    {
                                        loLoanApplicationDetail.DetailId          = "";
                                        loLoanApplicationDetail.LoanApplicationId = _LoanApplicationId;
                                        loLoanApplicationDetail.SeqNo             = i;
                                        loLoanApplicationDetail.Date              = _startDate;
                                        loLoanApplicationDetail.AmountDue         = _TotalAmountDue - _InstallmentAmountDue;
                                        loLoanApplicationDetail.InstallmentAmount = _InstallmentAmountDue;
                                        loLoanApplicationDetail.PaymentAmount     = 0;
                                        loLoanApplicationDetail.RunningBalance    = _OriginalTotalAmountDue;
                                        loLoanApplicationDetail.NewBalance        = 0;
                                        loLoanApplicationDetail.Variance          = 0;
                                        loLoanApplicationDetail.PastDueReason     = "";
                                        loLoanApplicationDetail.Remarks           = "";
                                        loLoanApplicationDetail.UserId            = GlobalVariables.UserId;
                                        loLoanApplicationDetail.save(GlobalVariables.Operation.Add);
                                        _startDate      = _startDate.AddDays(1);
                                        _TotalAmountDue = _TotalAmountDue - _InstallmentAmountDue;
                                        i++;
                                    }
                                }

                                //lacking post to accounting system...

                                MessageBoxUI _mb1 = new MessageBoxUI("Loan Application record has been successfully posted!", GlobalVariables.Icons.Information, GlobalVariables.Buttons.OK);
                                _mb1.ShowDialog();
                                refresh();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBoxUI mb = new MessageBoxUI(ex, GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK);
                            mb.ShowDialog();
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnApprove_Click");
                em.ShowDialog();
                return;
            }
        }