public int Compare(object x, object y) { VendorBalance X = (VendorBalance)x; VendorBalance Y = (VendorBalance)y; return(new CaseInsensitiveComparer().Compare(X.PERIOD.ID, Y.PERIOD.ID)); }
public VendorBalance Create(Period newPeriod) { VendorBalance sCard = new VendorBalance(newPeriod, VENDOR, CURRENCY, VENDOR_BALANCE_TYPE); sCard.BALANCE = BALANCE; return(sCard); }
public static void SaveHeader(MySql.Data.MySqlClient.MySqlCommand cmd, VendorBalance sc) { cmd.CommandText = sc.GetInsertSQL(); cmd.ExecuteNonQuery(); cmd.CommandText = VendorBalance.SelectMaxIDSQL(); sc.ID = Convert.ToInt32(cmd.ExecuteScalar()); }
//public static VendorBalance FindVendorBalance(MySql.Data.MySqlClient.MySqlCommand cmd, long periodId) //{ // cmd.CommandText = String.Format("select * from table_vendorbalance where period_id = {0}", periodId); // MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader(); // VendorBalance sc = VendorBalance.TransformReader(r); // r.Close(); // return sc; //} public static IList FindVendorBalanceByPeriod(MySql.Data.MySqlClient.MySqlCommand cmd, long periodId) { cmd.CommandText = String.Format("select * from table_vendorbalance where period_id = {0}", periodId); MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader(); IList sc = VendorBalance.TransformReaderList(r); r.Close(); return(sc); }
public VendorBalanceEntry(VendorBalance vendorBalance, EventJournalItem item) { VENDOR_BALANCE = vendorBalance; VENDOR_BALANCE_ENTRY_TYPE = item.VENDOR_BALANCE_ENTRY_TYPE; TRANSACTION_DATE = item.EVENT_JOURNAL.TRANSACTION_DATE; CURRENCY = item.CURRENCY; item.VENDOR_BALANCE_ENTRY = this; EVENT_JOURNAL_ITEM = item; AMOUNT = item.AMOUNT; }
protected void SetVendorBalance(EventJournalItem item, Period period) { VendorBalance sc = VendorBalanceRepository.FindVendorBalanceHeader(m_command, item.VENDOR.ID, item.CURRENCY.ID, period.ID, item.VENDOR_BALANCE_TYPE); if (sc == null) { sc = VendorBalance.CreateVendorBalance(item, period); } item.VENDOR_BALANCE = sc; }
protected void updateVendorBalances(VendorBalance vb) { if (vb.ID > 0) { VendorBalanceRepository.UpdateHeader(m_command, vb); } else if (vb.ID == 0) { VendorBalanceRepository.SaveHeader(m_command, vb); } }
public static void Save(MySql.Data.MySqlClient.MySqlCommand cmd, VendorBalance sc) { cmd.CommandText = sc.GetInsertSQL(); cmd.ExecuteNonQuery(); cmd.CommandText = VendorBalance.SelectMaxIDSQL(); sc.ID = Convert.ToInt32(cmd.ExecuteScalar()); foreach (VendorBalanceEntry sce in sc.VENDOR_BALANCE_ENTRIES) { cmd.CommandText = sce.GetInsertSQL(); cmd.ExecuteNonQuery(); cmd.CommandText = VendorBalanceEntry.SelectMaxIDSQL(); sce.ID = Convert.ToInt32(cmd.ExecuteScalar()); } }
public static VendorBalance FindVendorBalanceHeader(MySql.Data.MySqlClient.MySqlCommand cmd, long vendor, long currency, long periodId, VendorBalanceType type) { cmd.CommandText = String.Format("select * from table_vendorbalance where vendor_id = {0} and ccy_id = {1} and period_id = {2} and vb_vendorbalancetype = '{3}'", vendor, currency, periodId, type.ToString()); MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader(); VendorBalance sc = VendorBalance.TransformReader(r); r.Close(); if (sc != null) { sc.PERIOD = PeriodRepository.FindPeriod(cmd, sc.PERIOD.ID); } return(sc); }
public static IList TransformReaderList(MySql.Data.MySqlClient.MySqlDataReader a) { IList result = new ArrayList(); while (a.Read()) { VendorBalance vb = new VendorBalance(); vb.ID = Convert.ToInt32(a["vb_id"]); vb.VENDOR_BALANCE_TYPE = (VendorBalanceType)Enum.Parse(typeof(VendorBalanceType), a["vb_vendorbalancetype"].ToString()); vb.PERIOD = new Period(Convert.ToInt32(a["period_id"])); vb.VENDOR = vb.VENDOR_BALANCE_TYPE == VendorBalanceType.Supplier ? (Vendor) new Supplier(Convert.ToInt32(a["vendor_id"])) : (Vendor) new Customer(Convert.ToInt32(a["vendor_id"])); vb.BALANCE = Convert.ToDouble(a["vb_balance"]); vb.CURRENCY = new Currency(Convert.ToInt32(a["ccy_id"])); result.Add(vb); } return(result); }
public IList GetVendorBalances(int supID) { ArrayList result = new ArrayList(); OpenConnection(); MySql.Data.MySqlClient.MySqlDataReader r; m_cmd.CommandText = VendorBalance.FindByVendorBalanceByCustomer(supID); r = m_cmd.ExecuteReader(); IList vbe = VendorBalance.TransformReaderList(r); r.Close(); foreach (VendorBalance v in vbe) { result.Add(v); } result.Sort(new VendorBalanceComparer()); return(result); }
protected void updateVendorBalances(IList items) { foreach (EventJournalItem item in items) { VendorBalance sc = item.VENDOR_BALANCE; if (sc.ID > 0) { VendorBalanceRepository.UpdateHeader(m_command, sc); } else if (sc.ID == 0) { VendorBalanceRepository.SaveHeader(m_command, sc); } if (item.VENDOR_BALANCE_ENTRY != null) { VendorBalanceEntryRepository.Save(m_command, item.VENDOR_BALANCE_ENTRY); } } }
public static void Update(MySql.Data.MySqlClient.MySqlCommand cmd, VendorBalance sc) { cmd.CommandText = sc.GetUpdateSQL(); cmd.ExecuteNonQuery(); foreach (VendorBalanceEntry sce in sc.VENDOR_BALANCE_ENTRIES) { if (sce.ID == 0) { cmd.CommandText = sce.GetInsertSQL(); cmd.ExecuteNonQuery(); cmd.CommandText = VendorBalanceEntry.SelectMaxIDSQL(); sce.ID = Convert.ToInt32(cmd.ExecuteScalar()); } else { cmd.CommandText = sce.GetUpdateSQL(); cmd.ExecuteNonQuery(); } } cmd.CommandText = VendorBalanceEntry.FindByVendorBalance(sc.ID); MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader(); IList sces = VendorBalanceEntry.TransformReaderList(r); r.Close(); foreach (VendorBalanceEntry sce in sces) { sce.UPDATED = sc.VENDOR_BALANCE_ENTRIES.Contains(sce); } foreach (VendorBalanceEntry sce in sces) { if (!sce.UPDATED) { cmd.CommandText = VendorBalanceEntry.DeleteSQL(sce.ID); cmd.ExecuteNonQuery(); } } }
public void ProcessTransaction(int currentPeriodId, Employee emp) { OpenConnection(); MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction(); try { m_command.Transaction = trc; Period crntPeriod = PeriodRepository.FindPeriod(m_command, currentPeriodId) as Period; if (crntPeriod == null) { throw new Exception("Current Period Not Found!"); } if (crntPeriod.PERIOD_STATUS != PeriodStatus.Current) { throw new Exception("Period is not in Active Month!"); } GeneralSetup gs = GeneralSetupRepository.GetGeneralSetup(m_command); if (gs.START_ENTRY_PERIOD == null) { throw new Exception("Start Entry Month Not Found!"); } IList invTrs = this.GetAllCodeListOfNotPostedEvent(crntPeriod.START_DATE, crntPeriod.END_DATA); string invCodes = string.Empty; if (invTrs.Count > 0) { foreach (string code in invTrs) { invCodes += code + "\r\n"; } } if (invTrs.Count > 0) { throw new Exception("Please Post Transaction : \r\n" + invCodes); } Period nextPeriod = this.GetNextPeriod(crntPeriod) as Period; if (nextPeriod == null) { throw new Exception("Next Period Not Define!"); } IList stockcards = StockCardRepository.FindStockCardByPeriod(m_command, crntPeriod.ID); nextPeriod.PERIOD_STATUS = PeriodStatus.Current; nextPeriod.CLOSED_DATE = DateTime.Now; PeriodRepository.UpdatePeriod(m_command, nextPeriod); crntPeriod.PERIOD_STATUS = PeriodStatus.Close; crntPeriod.CLOSED_DATE = DateTime.Now; PeriodRepository.UpdatePeriod(m_command, crntPeriod); IList newSCards = new ArrayList(); OpeningStock ops = new OpeningStock(); ops.TRANSACTION_DATE = nextPeriod.START_DATE; ops.CURRENCY = CurrencyRepository.GetBaseCurrency(m_command); ops.DOCUMENT_DATE = DateTime.Today; ops.EMPLOYEE = emp; ops.MODIFIED_BY = emp.NAME; ops.MODIFIED_DATE = DateTime.Today; ops.NOTES = "AUTO" + nextPeriod.START_DATE.ToString(Utils.DATE_FORMAT_SHORT); ops.NOTICE_DATE = DateTime.Today; ops.WAREHOUSE = getCommonStore(); double total = 0; for (int i = 0; i < stockcards.Count; i++) { StockCard sCard = stockcards[i] as StockCard; if (sCard.BALANCE == 0) { continue; } OpeningStockItem opi = new OpeningStockItem(); opi.EVENT = ops; opi.PART = sCard.PART; opi.PRICE = PartRepository.GetLatestPriceMovementItemPeriod(m_command, sCard.PART.ID, crntPeriod.START_DATE, crntPeriod.END_DATA); opi.QYTAMOUNT = sCard.BALANCE; opi.TOTAL_AMOUNT = opi.PRICE * sCard.BALANCE; Part p = PartRepository.GetByID(m_command, sCard.PART.ID); opi.UNIT = p.UNIT; opi.WAREHOUSE = sCard.WAREHOUSE; ops.EVENT_ITEMS.Add(opi); total += opi.TOTAL_AMOUNT; // newSCards.Add(sCard.Create(nextPeriod)); } ops.AMOUNT = total; r_openingStock.SaveNoTransaction(ops, m_command); r_openingStock.ConfirmNoTransaction(ops.ID, m_command); //foreach (StockCard sc in newSCards) //{ // StockCardRepository.SaveHeader(m_command, sc); // } IList vbalances = VendorBalanceRepository.FindVendorBalanceByPeriod(m_command, crntPeriod.ID); IList newvbalances = new ArrayList(); for (int i = 0; i < vbalances.Count; i++) { VendorBalance vb = vbalances[i] as VendorBalance; newvbalances.Add(vb.Create(nextPeriod)); //if (vb.VENDOR_BALANCE_TYPE == VendorBalanceType.Customer) //{ // CustomerOutStandingInvoice cosi = new CustomerOutStandingInvoice(); // cosi.CURRENCY = vb.CURRENCY; // cosi.TRANSACTION_DATE = nextPeriod.START_DATE; // cosi.EMPLOYEE = emp; // cosi.MODIFIED_BY = emp.NAME; // cosi.MODIFIED_COMPUTER_NAME = Environment.MachineName; // cosi.MODIFIED_DATE = DateTime.Now; // cosi.NOTES = "AUTO"; // cosi.NOTICE_DATE = DateTime.Now; // cosi.VENDOR = vb.VENDOR; // CustomerOutStandingInvoiceItem cosii = new CustomerOutStandingInvoiceItem(); // cosii.EVENT_JOURNAL = cosi; // cosii.INVOICE_NO = "AUTO_OPENING_BALANCE"; // cosii.INVOICE_DATE = DateTime.Today; // cosii.TOP = getCommonTOP(); // cosii.DUE_DATE = DateTime.Today; // cosii.EMPLOYEE = emp; // cosii.AMOUNT = vb.BALANCE; // cosii. //} } foreach (VendorBalance sc in newvbalances) { VendorBalanceRepository.SaveHeader(m_command, sc); } trc.Commit(); } catch (Exception x) { trc.Rollback(); throw x; } }
public static void DeleteHeader(MySql.Data.MySqlClient.MySqlCommand cmd, VendorBalance sc) { cmd.CommandText = sc.GetDeleteSQL(); cmd.ExecuteNonQuery(); }