protected override void doUpdateNoTransaction(EventJournal en)
        {
            try
            {
                APDebitNote e = (APDebitNote)en;
                m_command.CommandText = e.GetUpdateSQL();
                m_command.ExecuteNonQuery();

                foreach (APDebitNoteItem 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 = APDebitNoteItem.SelectMaxIDSQL();
                        sti.ID = Convert.ToInt32(m_command.ExecuteScalar());
                    }
                }
                m_command.CommandText = APDebitNoteItem.DeleteUpdate(e.ID, e.EVENT_JOURNAL_ITEMS);
                m_command.ExecuteNonQuery();
            }
            catch (Exception x)
            {
                throw x;
            }
        }
        protected override void doUpdate(EventJournal en)
        {
            MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction();
            m_command.Transaction = trc;
            try
            {
                APDebitNote e = (APDebitNote)en;
                m_command.CommandText = e.GetUpdateSQL();
                m_command.ExecuteNonQuery();

                foreach (APDebitNoteItem 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 = APDebitNoteItem.SelectMaxIDSQL();
                        sti.ID = Convert.ToInt32(m_command.ExecuteScalar());
                    }
                }
                m_command.CommandText = APDebitNoteItem.DeleteUpdate(e.ID, e.EVENT_JOURNAL_ITEMS);
                m_command.ExecuteNonQuery();
                trc.Commit();
            }
            catch (Exception x)
            {
                trc.Rollback();
                throw x;
            }
        }
        public int RecordCount()
        {
            m_command.CommandText = APDebitNote.RecordCount();
            int result = Convert.ToInt32(m_command.ExecuteScalar());

            return(result);
        }
        protected override void doSaveNoTransaction(EventJournal e)
        {
            try
            {
                DateTime     trDate     = DateTime.Today;
                string       codesample = AutoNumberSetupRepository.GetCodeSampleByDomainName(m_command, "APDebitNote");
                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, "APDebitNote", e.CODE, lastCode, lastDate, trDate, trCount == 0);

                APDebitNote stk = (APDebitNote)e;
                m_command.CommandText = stk.GetInsertSQL();
                m_command.ExecuteNonQuery();
                m_command.CommandText = APDebitNote.SelectMaxIDSQL();
                stk.ID = Convert.ToInt32(m_command.ExecuteScalar());
                foreach (APDebitNoteItem item in stk.EVENT_JOURNAL_ITEMS)
                {
                    m_command.CommandText = item.GetInsertSQL();
                    m_command.ExecuteNonQuery();
                    m_command.CommandText = APDebitNoteItem.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 = APDebitNote.GetByIDSQL(ID);
            MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader();
            APDebitNote st = APDebitNote.TransformReader(r);

            r.Close();
            m_command.CommandText = APDebitNoteItem.GetByEventIDSQL(ID);
            r = m_command.ExecuteReader();
            IList stis = APDebitNoteItem.TransformReaderList(r);

            r.Close();
            foreach (APDebitNoteItem 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.PURCHASE_RETURN != null)
                {
                    if (sti.PURCHASE_RETURN.ID > 0)
                    {
                        sti.PURCHASE_RETURN = PurchaseReturnRepository.GetPurchaseReturnForDebitNote(m_command, sti.PURCHASE_RETURN);
                    }
                }
                st.EVENT_JOURNAL_ITEMS.Add(sti);
            }
            return(st);
        }
Exemple #6
0
        protected override void doDelete(EventJournal e)
        {
            Payment st = (Payment)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");
                }
                foreach (PaymentItem sti in e.EVENT_JOURNAL_ITEMS)
                {
                    if (sti.PAYMENT_TYPE == PaymentType.APDebitNote)
                    {
                        m_command.CommandText = APDebitNote.UpdateUsedForPayment(sti.AP_DEBIT_NOTE.ID, false);
                        m_command.ExecuteNonQuery();
                    }
                }
                m_command.CommandText = PaymentItem.DeleteAllByEventSQL(st.ID);
                m_command.ExecuteNonQuery();
                m_command.CommandText = Payment.DeleteSQL(st.ID);
                m_command.ExecuteNonQuery();
                trc.Commit();
            }
            catch (Exception x)
            {
                trc.Rollback();
                throw x;
            }
        }
Exemple #7
0
        public static APDebitNote TransformReader(MySql.Data.MySqlClient.MySqlDataReader r)
        {
            APDebitNote tr = null;

            if (r.HasRows)
            {
                r.Read();
                tr                           = new APDebitNote();
                tr.ID                        = Convert.ToInt32(r["apdn_id"]);
                tr.CODE                      = r["apdn_code"].ToString();
                tr.TRANSACTION_DATE          = Convert.ToDateTime(r["apdn_date"]);
                tr.VENDOR                    = new Supplier(Convert.ToInt32(r["sup_id"]));
                tr.CURRENCY                  = new Currency(Convert.ToInt32(r["ccy_id"]));
                tr.VENDOR_BALANCE_ENTRY_TYPE = VendorBalanceEntryType.APDebitNote;
                tr.NOTES                     = r["apdn_notes"].ToString();
                tr.POSTED                    = Convert.ToBoolean(r["apdn_posted"]);
                tr.EVENT_STATUS              = (EventStatus)Enum.Parse(typeof(EventStatus), r["apdn_eventstatus"].ToString());
                tr.SUBTOTAL_AMOUNT           = Convert.ToDouble(r["apdn_subtotalamount"]);
                tr.DISC_PERCENT              = Convert.ToDouble(r["apdn_discpercent"]);
                tr.AMOUNT_AFTER_DISC_PERCENT = Convert.ToDouble(r["apdn_amountafterdiscpercent"]);
                tr.DISC_AMOUNT               = Convert.ToDouble(r["apdn_discamount"]);
                tr.AMOUNT_AFTER_DISC_AMOUNT  = Convert.ToDouble(r["apdn_amountafterdiscamount"]);
                tr.OTHER_EXPENSE             = Convert.ToDouble(r["apdn_otherexpense"]);
                tr.NET_AMOUNT                = Convert.ToDouble(r["apdn_netamount"]);
                tr.EMPLOYEE                  = new Employee(Convert.ToInt32(r["emp_id"]));
                tr.USED_FOR_PAYMENT          = Convert.ToBoolean(r["apdn_usedforpayment"]);
                tr.MODIFIED_BY               = r["modified_by"].ToString();
                tr.MODIFIED_DATE             = Convert.ToDateTime(r["modified_date"].ToString());
                tr.MODIFIED_COMPUTER_NAME    = r["modified_computer"].ToString();
            }
            return(tr);
        }
        private EventStatus getEventStatus(int id)
        {
            m_command.CommandText = APDebitNote.GetEventStatus(id);
            object      b = m_command.ExecuteScalar();
            EventStatus m = (EventStatus)Enum.Parse(typeof(EventStatus), b.ToString());

            return(m);
        }
        public static APDebitNote FindAPDNForPayment(MySql.Data.MySqlClient.MySqlCommand m_command, int apdnID)
        {
            m_command.CommandText = APDebitNote.GetByIDSQL(apdnID);
            MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader();
            APDebitNote reuslt = APDebitNote.TransformReader(r);

            r.Close();
            return(reuslt);
        }
        public override EventJournal FindLastCodeAndTransactionDate(string codesample)
        {
            m_command.CommandText = APDebitNote.FindLastCodeAndTransactionDate(codesample);
            MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader();
            EventJournal e = APDebitNote.TransformReader(r);

            r.Close();
            return(e);
        }
Exemple #11
0
        protected override void doUpdate(EventJournal en)
        {
            MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction();
            m_command.Transaction = trc;
            try
            {
                Payment e = (Payment)en;
                m_command.CommandText = e.GetUpdateSQL();
                m_command.ExecuteNonQuery();

                foreach (PaymentItem sti in e.EVENT_JOURNAL_ITEMS)
                {
                    sti.VENDOR_BALANCE_SUPPLIER_INVOICE_TYPE = sti.SUPPLIER_INVOICE_JOURNAL_ITEM.GET_EVENT_JOURNAL.VENDOR_BALANCE_ENTRY_TYPE;
                    if (sti.ID > 0)
                    {
                        m_command.CommandText = sti.GetUpdateSQL();
                        m_command.ExecuteNonQuery();
                    }
                    else
                    {
                        m_command.CommandText = sti.GetInsertSQL();
                        m_command.ExecuteNonQuery();
                        m_command.CommandText = PaymentItem.SelectMaxIDSQL();
                        sti.ID = Convert.ToInt32(m_command.ExecuteScalar());
                    }
                    if (sti.PAYMENT_TYPE == PaymentType.APDebitNote)
                    {
                        m_command.CommandText = APDebitNote.UpdateUsedForPayment(sti.AP_DEBIT_NOTE.ID, true);
                        m_command.ExecuteNonQuery();
                    }
                }
                m_command.CommandText = PaymentItem.GetNotInTypeAPDN(e.ID, e.EVENT_JOURNAL_ITEMS);
                MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader();
                IList pymnts = PaymentItem.TransformReaderList(r);
                r.Close();
                foreach (PaymentItem itm in pymnts)
                {
                    m_command.CommandText = APDebitNote.UpdateUsedForPayment(itm.AP_DEBIT_NOTE.ID, false);
                    m_command.ExecuteNonQuery();
                }


                m_command.CommandText = PaymentItem.DeleteUpdate(e.ID, e.EVENT_JOURNAL_ITEMS);
                m_command.ExecuteNonQuery();
                trc.Commit();
            }
            catch (Exception x)
            {
                trc.Rollback();
                throw x;
            }
        }
 protected override bool doIsCodeExist(string code)
 {
     try
     {
         m_command.CommandText = APDebitNote.SelectCountByCode(code);
         int t = Convert.ToInt32(m_command.ExecuteScalar());
         return(t > 0);
     }
     catch (Exception x)
     {
         throw x;
     }
 }
        //public static APDebitNoteItem FindGRNItem(MySql.Data.MySqlClient.MySqlCommand cmd, int grnIID)
        //{
        //    cmd.CommandText = APDebitNoteItem.FindByGrnItemIDSQL(grnIID);
        //    MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader();
        //    APDebitNoteItem res = APDebitNoteItem.TransformReader(r);
        //    r.Close();
        //    cmd.CommandText = APDebitNote.GetByIDSQL(res.EVENT.ID);
        //    r = cmd.ExecuteReader();
        //    res.EVENT = APDebitNote.TransformReader(r);
        //    r.Close();
        //    return res;
        //}

        protected override IList doSearch(string find)
        {
            try
            {
                m_command.CommandText = APDebitNote.GetSearch(find);
                MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader();
                IList rest = APDebitNote.TransformReaderList(r);
                r.Close();
                return(rest);
            }
            catch (Exception x)
            {
                throw x;
            }
        }
        internal static IList FindAPDNByPurchaseReturn(MySql.Data.MySqlClient.MySqlCommand cmd, int prID)
        {
            cmd.CommandText = APDebitNoteItem.GetAPDNItemByPRID(prID);
            MySql.Data.MySqlClient.MySqlDataReader r = cmd.ExecuteReader();
            IList result = APDebitNoteItem.TransformReaderList(r);

            r.Close();
            foreach (APDebitNoteItem i in result)
            {
                cmd.CommandText = APDebitNote.GetByIDSQL(i.EVENT_JOURNAL.ID);
                r = cmd.ExecuteReader();
                i.EVENT_JOURNAL = APDebitNote.TransformReader(r);
                r.Close();
            }
            return(result);
        }
Exemple #15
0
        protected override void doSave(EventJournal e)
        {
            MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction();
            try
            {
                m_command.Transaction = trc;

                DateTime     trDate     = DateTime.Today;
                string       codesample = AutoNumberSetupRepository.GetCodeSampleByDomainName(m_command, "Payment");
                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, "Payment", e.CODE, lastCode, lastDate, trDate, trCount == 0);

                Payment stk = (Payment)e;
                m_command.CommandText = stk.GetInsertSQL();
                m_command.ExecuteNonQuery();
                m_command.CommandText = Payment.SelectMaxIDSQL();
                stk.ID = Convert.ToInt32(m_command.ExecuteScalar());
                foreach (PaymentItem item in stk.EVENT_JOURNAL_ITEMS)
                {
                    item.VENDOR_BALANCE_SUPPLIER_INVOICE_TYPE = item.SUPPLIER_INVOICE_JOURNAL_ITEM.GET_EVENT_JOURNAL.VENDOR_BALANCE_ENTRY_TYPE;
                    m_command.CommandText = item.GetInsertSQL();
                    m_command.ExecuteNonQuery();
                    m_command.CommandText = PaymentItem.SelectMaxIDSQL();
                    item.ID = Convert.ToInt32(m_command.ExecuteScalar());
                    if (item.PAYMENT_TYPE == PaymentType.APDebitNote)
                    {
                        m_command.CommandText = APDebitNote.UpdateUsedForPayment(item.AP_DEBIT_NOTE.ID, true);
                        m_command.ExecuteNonQuery();
                    }
                }
                trc.Commit();
            }
            catch (Exception x)
            {
                e.ID = 0;
                foreach (EventJournalItem item in e.EVENT_JOURNAL_ITEMS)
                {
                    item.ID = 0;
                }
                trc.Rollback();
                throw x;
            }
        }
        public IList FindAPDNForPayment(int supID, DateTime trdate, string find, IList notInID)
        {
            StringBuilder poisSB = new StringBuilder();

            foreach (int i in notInID)
            {
                poisSB.Append(i.ToString());
                poisSB.Append(',');
            }
            string pois = poisSB.ToString();

            pois = notInID.Count > 0 ? pois.Substring(0, pois.Length - 1) : "";

            m_command.CommandText = APDebitNote.GetForPayment(supID, trdate, find, pois);
            MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader();
            IList reuslt = APDebitNote.TransformReaderList(r);

            r.Close();
            return(reuslt);
        }
        protected override void doDeleteNoTransaction(EventJournal e)
        {
            APDebitNote st = (APDebitNote)e;

            try
            {
                if (getEventStatus(st.ID) == EventStatus.Confirm)
                {
                    throw new Exception("Revise before delete");
                }
                m_command.CommandText = APDebitNoteItem.DeleteAllByEventSQL(st.ID);
                m_command.ExecuteNonQuery();
                m_command.CommandText = APDebitNote.DeleteSQL(st.ID);
                m_command.ExecuteNonQuery();
            }
            catch (Exception x)
            {
                throw x;
            }
        }
        protected override void doDelete(EventJournal e)
        {
            APDebitNote st = (APDebitNote)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 = APDebitNoteItem.DeleteAllByEventSQL(st.ID);
                m_command.ExecuteNonQuery();
                m_command.CommandText = APDebitNote.DeleteSQL(st.ID);
                m_command.ExecuteNonQuery();
                trc.Commit();
            }
            catch (Exception x)
            {
                trc.Rollback();
                throw x;
            }
        }
Exemple #19
0
        public IList GetAllTransactions(int supID)
        {
            ArrayList result = new ArrayList();

            OpenConnection();
            MySql.Data.MySqlClient.MySqlDataReader r;

            m_cmd.CommandText = PurchaseOrder.GetBySupplierSQL(supID);
            r = m_cmd.ExecuteReader();
            IList po = PurchaseOrder.TransformReaderList(r);

            r.Close();
            foreach (Event e in po)
            {
                result.Add(e);
            }

            m_cmd.CommandText = GoodReceiveNote.GetBySupplierSQL(supID);
            r = m_cmd.ExecuteReader();
            IList grn = GoodReceiveNote.TransformReaderList(r);

            r.Close();
            foreach (Event e in grn)
            {
                result.Add(e);
            }

            m_cmd.CommandText = SupplierInvoice.GetBySupplierSQL(supID);
            r = m_cmd.ExecuteReader();
            IList si = SupplierInvoice.TransformReaderList(r);

            r.Close();
            foreach (Event e in si)
            {
                result.Add(e);
            }

            m_cmd.CommandText = PurchaseReturn.GetBySupplierSQL(supID);
            r = m_cmd.ExecuteReader();
            IList pr = PurchaseReturn.TransformReaderList(r);

            r.Close();
            foreach (Event e in pr)
            {
                result.Add(e);
            }

            m_cmd.CommandText = APDebitNote.GetBySupplierSQL(supID);
            r = m_cmd.ExecuteReader();
            IList apdn = APDebitNote.TransformReaderList(r);

            r.Close();
            foreach (EventJournal e in apdn)
            {
                result.Add(e);
            }

            m_cmd.CommandText = Payment.GetBySupplierSQL(supID);
            r = m_cmd.ExecuteReader();
            IList py = Payment.TransformReaderList(r);

            r.Close();
            foreach (EventJournal e in py)
            {
                result.Add(e);
            }

            m_cmd.CommandText = SupplierOutStandingInvoice.GetBySupplierSQL(supID);
            r = m_cmd.ExecuteReader();
            IList soi = SupplierOutStandingInvoice.TransformReaderList(r);

            r.Close();
            foreach (EventJournal e in soi)
            {
                result.Add(e);
            }

            result.Sort(new EventDateComparer());
            return(result);
        }
 protected override void doUpdateStatus(EventJournal e, bool posted)
 {
     m_command.CommandText = APDebitNote.GetUpdateStatusSQL(e);
     m_command.ExecuteNonQuery();
 }