예제 #1
0
        public void SaveFromClosingPeriod(DebtBalance debtBalance)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    Guid ID = Guid.NewGuid();

                    tx = em.BeginTransaction();

                    string[] columns = { "ID",            "BalanceYear", "BalanceMonth", "PurchaseCode", "PurchaseDate",  "SupplierId",
                                         "PaymentMethod", "GrandTotal",  "IsStatus",     "Notes",        "AmountInWords", "DueDate",   "TermOfPayment",
                                         "CreatedDate",   "ModifiedDate" };

                    object[] values = { ID,                               debtBalance.BalanceYear,                 debtBalance.BalanceMonth,         debtBalance.PurchaseCode, debtBalance.PurchaseDate.ToShortDateString(), debtBalance.SupplierId,
                                        debtBalance.PaymentMethod,        debtBalance.GrandTotal,                  debtBalance.IsStatus == true?1:0, debtBalance.Notes,
                                        debtBalance.AmountInWords,        debtBalance.DueDate.ToShortDateString(), debtBalance.TermOfPayment,
                                        DateTime.Now.ToShortDateString(), DateTime.Now.ToShortDateString() };

                    var q = new Query().Select(columns).From(tableName).Insert(values);

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();
                throw ex;
            }
        }
예제 #2
0
        private void tsbDelete_Click(object sender, EventArgs e)
        {
            var userAccess = userAccessRepository.GetAll();

            bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser &&
                                               u.ObjectName == "Saldo Awal Hutang" && u.IsDelete);

            if (isAllowed == false && Store.IsAdministrator == false)
            {
                MessageBox.Show("Anda tidak dapat menghapus", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (Store.IsPeriodClosed)
                {
                    MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    DebtBalance debtBalance = debtBalanceRepository.GetById(new Guid(txtID.Text));
                    if (debtBalance.IsStatus == true)
                    {
                        MessageBox.Show("Tidak bisa menghapus " + "\n\n" + "Dokumen : " + txtPurchaseCode.Text + "\n\n" + "dipakai di Pembayaran Hutang ", "Perhatian",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (MessageBox.Show("Anda yakin ingin menghapus '" + txtPurchaseCode.Text + "'", "Perhatian",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            debtBalanceRepository.Delete(new Guid(txtID.Text), txtPurchaseCode.Text);
                            GetLastDebtBalance();
                            LoadDebtBalance();
                        }

                        if (lvwDebtBalance.Items.Count == 0)
                        {
                            tsbEdit.Enabled       = false;
                            tsbDelete.Enabled     = false;
                            tsbRefresh.Enabled    = false;
                            tsbMenuFilter.Enabled = false;
                            txtSearch.Enabled     = false;
                            tsbFilter.Enabled     = false;

                            ClearForm();
                        }
                    }
                }
            }
        }
예제 #3
0
        public void Update(DebtBalance debtBalance)
        {
            Transaction tx = null;

            try
            {
                using (var em = EntityManagerFactory.CreateInstance(ds))
                {
                    tx = em.BeginTransaction();

                    decimal oldGrandTotal  = 0;
                    var     oldDebtBalance = GetById(debtBalance.ID);
                    if (oldDebtBalance != null)
                    {
                        oldGrandTotal = oldDebtBalance.GrandTotal;

                        supplierRepository.MinusFirstBalance(debtBalance.SupplierId, oldGrandTotal);
                    }


                    string[] columns = { "BalanceYear",   "BalanceMonth", "PurchaseCode", "PurchaseDate", "SupplierId",
                                         "PaymentMethod", "Notes",        "GrandTotal",   "IsStatus",     "AmountInWords","DueDate","TermOfPayment",
                                         "ModifiedDate" };

                    object[] values = { debtBalance.BalanceYear,   debtBalance.BalanceMonth, debtBalance.PurchaseCode,  debtBalance.PurchaseDate.ToShortDateString(), debtBalance.SupplierId,
                                        debtBalance.PaymentMethod, debtBalance.Notes,        debtBalance.GrandTotal,    debtBalance.IsStatus == true?1:0,
                                        debtBalance.AmountInWords, debtBalance.DueDate,      debtBalance.TermOfPayment,
                                        DateTime.Now.ToShortDateString() };

                    var q = new Query().Select(columns).From(tableName).Update(values)
                            .Where("ID").Equal("{" + debtBalance.ID + "}");

                    em.ExecuteNonQuery(q.ToSql(), tx);

                    //copy to purchase
                    Purchase purchase = CopyToPurchase(debtBalance);
                    purchaseRepository.UpdateHeader(em, tx, purchase);


                    supplierRepository.PlusFirstBalance(debtBalance.SupplierId, debtBalance.GrandTotal);

                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                tx.Rollback();
                throw ex;
            }
        }
예제 #4
0
 private void lvwDebtBalance_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lvwDebtBalance.Items.Count > 0)
     {
         if (formMode == FormMode.Add || formMode == FormMode.Edit)
         {
         }
         else
         {
             DebtBalance debtBalance = debtBalanceRepository.GetById(new Guid(lvwDebtBalance.FocusedItem.Text));
             ViewDebtBalanceDetail(debtBalance);
         }
     }
 }
예제 #5
0
        private void PurchaseToDebtBalance()
        {
            var purchase = purchaseRepository.GetByStatusFalse();

            foreach (var s in purchase)
            {
                var oldDebtBalance = debtBalanceRepository.GetByMonthYear(Store.ActiveMonth, Store.ActiveYear, s.Code);

                DebtBalance debtBalance = new DebtBalance();
                if (oldDebtBalance == null)
                {
                    debtBalance.BalanceYear   = Store.ActiveYear;
                    debtBalance.BalanceMonth  = Store.ActiveMonth;
                    debtBalance.PurchaseCode  = s.Code;
                    debtBalance.PurchaseDate  = s.Date;
                    debtBalance.SupplierId    = s.SupplierId;
                    debtBalance.PaymentMethod = s.PaymentMethod;
                    debtBalance.IsStatus      = s.Status;
                    debtBalance.Notes         = s.Notes;
                    debtBalance.GrandTotal    = s.GrandTotal;
                    debtBalance.AmountInWords = s.AmountInWords;
                    debtBalance.DueDate       = s.DueDate;
                    debtBalance.TermOfPayment = s.TermOfPayment;

                    debtBalanceRepository.SaveFromClosingPeriod(debtBalance);
                }
                else
                {
                    debtBalance.ID            = oldDebtBalance.ID;
                    debtBalance.BalanceYear   = Store.ActiveYear;
                    debtBalance.BalanceMonth  = Store.ActiveMonth;
                    debtBalance.PurchaseCode  = s.Code;
                    debtBalance.PurchaseDate  = s.Date;
                    debtBalance.SupplierId    = s.SupplierId;
                    debtBalance.PaymentMethod = s.PaymentMethod;
                    debtBalance.IsStatus      = s.Status;
                    debtBalance.Notes         = s.Notes;
                    debtBalance.GrandTotal    = s.GrandTotal;
                    debtBalance.AmountInWords = s.AmountInWords;
                    debtBalance.DueDate       = s.DueDate;
                    debtBalance.TermOfPayment = s.TermOfPayment;

                    debtBalanceRepository.UpdateFromClosingPeriod(debtBalance);
                }
            }
        }
예제 #6
0
        public DebtBalance GetLast()
        {
            DebtBalance debtBalance = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                var sql = "SELECT TOP 1 db.ID, db.BalanceYear, db.BalanceMonth, db.PurchaseCode, db.PurchaseDate, db.SupplierId, s.SupplierName, "
                          + "db.PaymentMethod, db.GrandTotal, db.IsStatus, db.Notes, db.CreatedDate, db.ModifiedDate, "
                          + "db.AmountInWords, db.DueDate, db.TermOfPayment "
                          + "FROM DebtBalance db INNER JOIN Supplier s ON db.SupplierId = s.ID "
                          + "ORDER BY db.PurchaseCode DESC";

                debtBalance = em.ExecuteObject <DebtBalance>(sql, new DebtBalanceMapper());
            }

            return(debtBalance);
        }
예제 #7
0
        private Purchase CopyToPurchase(DebtBalance debtBalance)
        {
            Purchase purchase = new Purchase();

            purchase.Code          = debtBalance.PurchaseCode;
            purchase.Date          = debtBalance.PurchaseDate;
            purchase.SupplierId    = debtBalance.SupplierId;
            purchase.PaymentMethod = debtBalance.PaymentMethod;
            purchase.Status        = debtBalance.IsStatus;
            purchase.Notes         = debtBalance.Notes;
            purchase.GrandTotal    = debtBalance.GrandTotal;
            purchase.DueDate       = debtBalance.DueDate;
            purchase.AmountInWords = debtBalance.AmountInWords;
            purchase.PrintCounter  = 0;
            purchase.TermOfPayment = debtBalance.TermOfPayment;

            return(purchase);
        }
예제 #8
0
        public DebtBalance GetByMonthYear(int month, int year, string purchaseCode)
        {
            DebtBalance debtBalance = null;

            using (var em = EntityManagerFactory.CreateInstance(ds))
            {
                var sql = "SELECT db.ID, db.BalanceYear, db.BalanceMonth, db.PurchaseCode, db.PurchaseDate, db.SupplierId, s.SupplierName, "
                          + "db.PaymentMethod, db.GrandTotal, db.IsStatus, db.Notes, db.CreatedDate, db.ModifiedDate, "
                          + "db.AmountInWords, db.DueDate, db.TermOfPayment "
                          + "FROM DebtBalance db INNER JOIN Supplier s ON db.SupplierId = s.ID "
                          + "WHERE "
                          + "db.PurchaseCode like '%" + purchaseCode + "%' "
                          + "AND db.BalanceMonth=" + month + " AND db.BalanceYear=" + year + " "
                          + "ORDER BY db.PurchaseCode DESC";

                debtBalance = em.ExecuteObject <DebtBalance>(sql, new DebtBalanceMapper());
            }

            return(debtBalance);
        }
예제 #9
0
        private void tsbEdit_Click(object sender, EventArgs e)
        {
            var userAccess = userAccessRepository.GetAll();

            bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser &&
                                               u.ObjectName == "Saldo Awal Hutang" && u.IsEdit);

            if (isAllowed == false && Store.IsAdministrator == false)
            {
                MessageBox.Show("Anda tidak dapat merubah", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (Store.IsPeriodClosed)
                {
                    MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    DebtBalance debtBalance = debtBalanceRepository.GetById(new Guid(txtID.Text));
                    if (Store.ActiveMonth != Store.StartDate.Month || Store.ActiveYear != Store.StartDate.Year)
                    {
                        MessageBox.Show("Tanggal harus sesuai periode awal pemakaian" + "\n" + Store.GetMonthName(Store.StartDate.Month) + " " + Store.StartDate.Year, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (debtBalance.IsStatus == true)
                    {
                        MessageBox.Show("Tidak bisa diubah " + "\n\n" + "Dokumen : " + txtPurchaseCode.Text + "\n\n" + "dipakai di Pembayaran Hutang ", "Perhatian",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        formMode  = FormMode.Edit;
                        this.Text = "Saldo Awal Hutang - Edit";

                        EnableFormForEdit();
                    }
                }
            }
        }
예제 #10
0
        private void RenderDebtBalance(DebtBalance debtBalance)
        {
            var item = new ListViewItem(debtBalance.ID.ToString());

            item.SubItems.Add(debtBalance.PurchaseCode);
            item.SubItems.Add(debtBalance.PurchaseDate.ToString("dd/MM/yyyy"));
            item.SubItems.Add(debtBalance.Supplier.Name);
            item.SubItems.Add(debtBalance.DueDate.ToString("dd/MM/yyyy"));
            item.SubItems.Add(debtBalance.GrandTotal.ToString("N0").Replace(",", "."));

            if (debtBalance.IsStatus == true)
            {
                item.SubItems.Add("LUNAS");
            }
            else
            {
                item.SubItems.Add("BELUM LUNAS");
            }


            lvwDebtBalance.Items.Add(item);
        }
예제 #11
0
        private void GetLastDebtBalance()
        {
            int month = 0;
            int year  = 0;

            if (Store.ActiveMonth == 1)
            {
                month = 12;
                year  = Store.ActiveYear - 1;
            }
            else
            {
                month = Store.ActiveMonth - 1;
                year  = Store.ActiveYear;
            }

            DebtBalance debtBalance = debtBalanceRepository.GetLast(month, year);

            if (debtBalance != null)
            {
                ViewDebtBalanceDetail(debtBalance);
            }
        }
예제 #12
0
        private void ViewDebtBalanceDetail(DebtBalance debtBalance)
        {
            txtID.Text            = debtBalance.ID.ToString();
            txtPurchaseCode.Text  = debtBalance.PurchaseCode;
            dtpDate.Text          = debtBalance.PurchaseDate.ToShortDateString();
            dtpDueDate.Text       = debtBalance.DueDate.ToShortDateString();
            txtTermOfPayment.Text = debtBalance.TermOfPayment.ToString();

            txtSupplierId.Text   = debtBalance.SupplierId.ToString();
            txtSupplierName.Text = debtBalance.Supplier.Name;

            if (debtBalance.PaymentMethod == 1)
            {
                optCash.Checked = true;
            }
            else if (debtBalance.PaymentMethod == 2)
            {
                optCredit.Checked = true;
            }
            txtGrandTotal.Text  = debtBalance.GrandTotal.ToString();
            txtNotes.Text       = debtBalance.Notes;
            chkIsStatus.Checked = debtBalance.IsStatus;
        }
예제 #13
0
        private void GetDebtBalanceById(Guid id)
        {
            DebtBalance debtBalance = debtBalanceRepository.GetById(id);

            ViewDebtBalanceDetail(debtBalance);
        }
예제 #14
0
        private void SaveDebtBalance()
        {
            if (dtpDate.Value.Month >= Store.StartDate.Month && dtpDate.Value.Year >= Store.StartDate.Year)
            {
                MessageBox.Show("Tanggal harus sebelum periode awal pemakaian" + "\n" + Store.GetMonthName(Store.StartDate.Month) + " " + Store.StartDate.Year, "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (formMode == FormMode.Add && debtBalanceRepository.IsPurchaseCodeExisted(txtPurchaseCode.Text))
            {
                MessageBox.Show("Dokumen : \n\n" + txtPurchaseCode.Text + "\n\n" + "sudah ada ", "Perhatian",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (txtPurchaseCode.Text == "")
            {
                MessageBox.Show("Dokumen harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtPurchaseCode.Focus();
            }
            else if (txtSupplierName.Text == "")
            {
                MessageBox.Show("Supplier harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnBrowseSupplier.Focus();
            }
            else if (dtpDate.Value > dtpDueDate.Value)
            {
                MessageBox.Show("Tanggal jatuh tempo harus lebih besar dari tanggal transaksi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (txtGrandTotal.Text == "" || txtGrandTotal.Text == "0")
            {
                MessageBox.Show("Nilai harus lebih dari Nol", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGrandTotal.Focus();
            }
            else
            {
                DebtBalance debtBalance = new DebtBalance();

                debtBalance.BalanceYear  = Store.StartDate.Year;
                debtBalance.BalanceMonth = Store.StartDate.Month - 1;
                debtBalance.PurchaseCode = txtPurchaseCode.Text;
                debtBalance.PurchaseDate = dtpDate.Value;
                debtBalance.DueDate      = dtpDueDate.Value;
                debtBalance.SupplierId   = new Guid(txtSupplierId.Text);

                debtBalance.PaymentMethod = 2;

                debtBalance.GrandTotal = decimal.Parse(txtGrandTotal.Text.Replace(".", ""));
                debtBalance.Notes      = txtNotes.Text;

                string amountInWords = Store.GetAmounInWords(Convert.ToInt32(debtBalance.GrandTotal));
                string firstLetter   = amountInWords.Substring(0, 2).Trim().ToUpper();
                string theRest       = amountInWords.Substring(2, amountInWords.Length - 2);

                debtBalance.AmountInWords = firstLetter + theRest + " rupiah";
                debtBalance.IsStatus      = chkIsStatus.Checked;
                debtBalance.TermOfPayment = int.Parse(txtTermOfPayment.Text);

                if (formMode == FormMode.Add)
                {
                    debtBalanceRepository.Save(debtBalance);
                    GetLastDebtBalance();
                }
                else if (formMode == FormMode.Edit)
                {
                    debtBalance.ID = new Guid(txtID.Text);
                    debtBalanceRepository.Update(debtBalance);
                }

                LoadDebtBalance();
                DisableForm();

                formMode = FormMode.View;
            }
        }