protected override void doUpdate(EventJournal en) { MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction(); m_command.Transaction = trc; try { ARCreditNote e = (ARCreditNote)en; m_command.CommandText = e.GetUpdateSQL(); m_command.ExecuteNonQuery(); foreach (ARCreditNoteItem sti in e.EVENT_JOURNAL_ITEMS) { if (sti.ID > 0) { m_command.CommandText = sti.GetUpdateSQL(); m_command.ExecuteNonQuery(); } else { m_command.CommandText = sti.GetInsertSQL(); m_command.ExecuteNonQuery(); m_command.CommandText = ARCreditNoteItem.SelectMaxIDSQL(); sti.ID = Convert.ToInt32(m_command.ExecuteScalar()); } } m_command.CommandText = ARCreditNoteItem.DeleteUpdate(e.ID, e.EVENT_JOURNAL_ITEMS); m_command.ExecuteNonQuery(); trc.Commit(); } catch (Exception x) { trc.Rollback(); throw x; } }
protected override void doDelete(Event e) { SalesReturn st = (SalesReturn)e;//this.Get(e.ID); MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction(); m_command.Transaction = trc; try { if (getEventStatus(st.ID) == EventStatus.Confirm) { throw new Exception("Revise before delete"); } m_command.CommandText = ARCreditNoteItem.GetSRUsedByARCR(st.ID); int count = Convert.ToInt32(m_command.ExecuteScalar()); if (count > 0) { throw new Exception("Can not delete this Sales Return, this Sales Return used by ARCR"); } m_command.CommandText = SalesReturnItem.DeleteAllByEventSQL(st.ID); m_command.ExecuteNonQuery(); m_command.CommandText = SalesReturn.DeleteSQL(st.ID); m_command.ExecuteNonQuery(); trc.Commit(); } catch (Exception x) { trc.Rollback(); throw x; } }
protected override void doUpdateNoTransaction(EventJournal en) { try { ARCreditNote e = (ARCreditNote)en; m_command.CommandText = e.GetUpdateSQL(); m_command.ExecuteNonQuery(); foreach (ARCreditNoteItem sti in e.EVENT_JOURNAL_ITEMS) { if (sti.ID > 0) { m_command.CommandText = sti.GetUpdateSQL(); m_command.ExecuteNonQuery(); } else { m_command.CommandText = sti.GetInsertSQL(); m_command.ExecuteNonQuery(); m_command.CommandText = ARCreditNoteItem.SelectMaxIDSQL(); sti.ID = Convert.ToInt32(m_command.ExecuteScalar()); } } m_command.CommandText = ARCreditNoteItem.DeleteUpdate(e.ID, e.EVENT_JOURNAL_ITEMS); m_command.ExecuteNonQuery(); } catch (Exception x) { throw x; } }
protected override void doSaveNoTransaction(EventJournal e) { try { DateTime trDate = DateTime.Today; string codesample = AutoNumberSetupRepository.GetCodeSampleByDomainName(m_command, "ARCreditNote"); EventJournal codeDate = FindLastCodeAndTransactionDate(codesample); string lastCode = codeDate == null ? string.Empty : codeDate.CODE; DateTime lastDate = codeDate == null ? trDate : codeDate.TRANSACTION_DATE; int trCount = RecordCount(); e.CODE = AutoNumberSetupRepository.GetAutoNumberByDomainName(m_command, "ARCreditNote", e.CODE, lastCode, lastDate, trDate, trCount == 0); ARCreditNote stk = (ARCreditNote)e; m_command.CommandText = stk.GetInsertSQL(); m_command.ExecuteNonQuery(); m_command.CommandText = ARCreditNote.SelectMaxIDSQL(); stk.ID = Convert.ToInt32(m_command.ExecuteScalar()); foreach (ARCreditNoteItem item in stk.EVENT_JOURNAL_ITEMS) { m_command.CommandText = item.GetInsertSQL(); m_command.ExecuteNonQuery(); m_command.CommandText = ARCreditNoteItem.SelectMaxIDSQL(); item.ID = Convert.ToInt32(m_command.ExecuteScalar()); } } catch (Exception x) { e.ID = 0; foreach (EventJournalItem item in e.EVENT_JOURNAL_ITEMS) { item.ID = 0; } throw x; } }
protected override EventJournal doGet(int ID) { m_command.CommandText = ARCreditNote.GetByIDSQL(ID); MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader(); ARCreditNote st = ARCreditNote.TransformReader(r); r.Close(); m_command.CommandText = ARCreditNoteItem.GetByEventIDSQL(ID); r = m_command.ExecuteReader(); IList stis = ARCreditNoteItem.TransformReaderList(r); r.Close(); foreach (ARCreditNoteItem sti in stis) { sti.EVENT_JOURNAL = st; //sti.VENDOR = PartRepository.GetByID(m_command, sti.PART.ID); sti.VENDOR_BALANCE_ENTRY = VendorBalanceEntryRepository.FindVendorBalanceEntryByEventItem(m_command, sti.ID, sti.VENDOR_BALANCE_ENTRY_TYPE); //sti.GRN_ITEM = GoodReceiveNoteRepository.FindGoodReceiveNoteItem(m_command, sti.GRN_ITEM.ID); //sti.GRN_ITEM.PART = PartRepository.GetByID(m_command, sti.GRN_ITEM.PART.ID); if (sti.SALES_RETURN != null) { if (sti.SALES_RETURN.ID > 0) { sti.SALES_RETURN = SalesReturnRepository.GetSalesReturnForCreditNote(m_command, sti.SALES_RETURN); } } st.EVENT_JOURNAL_ITEMS.Add(sti); } return(st); }
public static IList TransformReaderList(MySql.Data.MySqlClient.MySqlDataReader aReader) { IList result = new ArrayList(); while (aReader.Read()) { ARCreditNoteItem transaction = new ARCreditNoteItem(); transaction.ID = Convert.ToInt32(aReader["arcri_id"]); transaction.EVENT_JOURNAL = new ARCreditNote(Convert.ToInt32(aReader["arcr_id"])); transaction.VENDOR = new Customer(Convert.ToInt32(aReader["cus_id"])); transaction.CURRENCY = new Currency(Convert.ToInt32(aReader["ccy_id"])); transaction.AMOUNT = Convert.ToDouble(aReader["arcri_amount"]); //transaction.VENDOR_BALANCE_ENTRY = new VendorBalanceEntry( //VENDOR_BALANCE == null ? 0 : VENDOR_BALANCE.ID, transaction.VENDOR_BALANCE_ENTRY_TYPE = VendorBalanceEntryType.ARCreditNote; transaction.INVOICE_DATE = Convert.ToDateTime(aReader["arcri_invoicedate"]); transaction.INVOICE_NO = aReader["arcri_invoiceno"].ToString(); transaction.DUE_DATE = Convert.ToDateTime(aReader["arcri_duedate"]); transaction.EMPLOYEE = new Employee(Convert.ToInt32(aReader["emp_id"])); transaction.DISCOUNT = Convert.ToDouble(aReader["arcri_discount"]); transaction.AMOUNT_BEFORE_DISCOUNT = Convert.ToDouble(aReader["arcri_amountbeforediscount"]); transaction.TOP = new TermOfPayment(Convert.ToInt32(aReader["top_id"])); transaction.DESCRIPTION = aReader["arcri_description"].ToString(); transaction.NOTES = aReader["arcri_notes"].ToString(); transaction.SALES_RETURN = new SalesReturn(Convert.ToInt32(aReader["srn_id"])); result.Add(transaction); } return(result); }
internal static IList FindARCRBySalesReturn(MySql.Data.MySqlClient.MySqlCommand cmd, int prID) { cmd.CommandText = ARCreditNoteItem.GetARCRItemBySRID(prID); MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader(); IList result = ARCreditNoteItem.TransformReaderList(r); r.Close(); foreach (ARCreditNoteItem i in result) { cmd.CommandText = ARCreditNote.GetByIDSQL(i.EVENT_JOURNAL.ID); r = cmd.ExecuteReader(); i.EVENT_JOURNAL = ARCreditNote.TransformReader(r); r.Close(); } return(result); }
protected override void doDeleteNoTransaction(EventJournal e) { ARCreditNote st = (ARCreditNote)e; try { if (getEventStatus(st.ID) == EventStatus.Confirm) { throw new Exception("Revise before delete"); } m_command.CommandText = ARCreditNoteItem.DeleteAllByEventSQL(st.ID); m_command.ExecuteNonQuery(); m_command.CommandText = ARCreditNote.DeleteSQL(st.ID); m_command.ExecuteNonQuery(); } catch (Exception x) { throw x; } }
protected override void doDelete(EventJournal e) { ARCreditNote st = (ARCreditNote)e; MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction(); m_command.Transaction = trc; try { if (getEventStatus(st.ID) == EventStatus.Confirm) { throw new Exception("Revise before delete"); } m_command.CommandText = ARCreditNoteItem.DeleteAllByEventSQL(st.ID); m_command.ExecuteNonQuery(); m_command.CommandText = ARCreditNote.DeleteSQL(st.ID); m_command.ExecuteNonQuery(); trc.Commit(); } catch (Exception x) { trc.Rollback(); throw x; } }
public IList FindSRForARCreditNote(string find, int supID, DateTime trdate, IList added) { m_command.CommandText = ARCreditNoteItem.GetSRUsedByARCR(); MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader(); if (r.HasRows) { while (r.Read()) { int id = Convert.ToInt32(r[0]); if (!added.Contains(id)) { added.Add(id); } } } r.Close(); StringBuilder poisSB = new StringBuilder(); foreach (int i in added) { poisSB.Append(i.ToString()); poisSB.Append(','); } string pois = poisSB.ToString(); pois = added.Count > 0 ? pois.Substring(0, pois.Length - 1) : ""; m_command.CommandText = SalesReturn.GetSearchSRNoForARCR(find, supID, pois, trdate); r = m_command.ExecuteReader(); IList result = SalesReturn.TransformReaderList(r); r.Close(); foreach (SalesReturn p in result) { m_command.CommandText = SalesReturnItem.GetByEventIDSQL(p.ID); r = m_command.ExecuteReader(); p.EVENT_ITEMS = SalesReturnItem.TransformReaderList(r); r.Close(); foreach (SalesReturnItem t in p.EVENT_ITEMS) { if ((t.DO_ITEM == null) && (t.DO_ITEM.ID == 0)) { continue; } m_command.CommandText = DeliveryOrderItem.GetByIDSQL(t.DO_ITEM.ID); r = m_command.ExecuteReader(); t.DO_ITEM = DeliveryOrderItem.TransformReader(r); r.Close(); if ((t.DO_ITEM.SO_ITEM == null)) { continue; } if (t.DO_ITEM.SO_ITEM.ID == 0) { continue; } m_command.CommandText = SalesOrderItem.GetByIDSQL(t.DO_ITEM.SO_ITEM.ID); r = m_command.ExecuteReader(); t.DO_ITEM.SO_ITEM = SalesOrderItem.TransformReader(r); r.Close(); t.DO_ITEM.PART = PartRepository.GetByID(m_command, t.DO_ITEM.PART.ID); t.DO_ITEM.PART.UNIT_CONVERSION_LIST = PartRepository.GetUnitConversionsStatic(m_command, t.DO_ITEM.SO_ITEM.PART.ID); t.PART = t.DO_ITEM.SO_ITEM.PART = t.DO_ITEM.PART; double subamount = (t.DO_ITEM.SO_ITEM.SUBTOTAL / t.DO_ITEM.SO_ITEM.GetAmountInSmallestUnit()) * t.GetAmountInSmallestUnit(); p.TOTAL_AMOUNT_FROM_SO += subamount; t.DO_ITEM.SO_ITEM.EVENT = SalesOrderRepository.GetHeaderOnly(m_command, t.DO_ITEM.SO_ITEM.EVENT.ID); p.CURRENCY = ((SalesOrder)t.DO_ITEM.SO_ITEM.EVENT).CURRENCY; } } return(result); }