protected override void doUpdate(EventJournal en)
        {
            MySql.Data.MySqlClient.MySqlTransaction trc = m_connection.BeginTransaction();
            m_command.Transaction = trc;
            try
            {
                SupplierOutStandingInvoice e = (SupplierOutStandingInvoice)en;
                m_command.CommandText = e.GetUpdateSQL();
                m_command.ExecuteNonQuery();

                foreach (SupplierOutStandingInvoiceItem 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 = SupplierOutStandingInvoiceItem.SelectMaxIDSQL();
                        sti.ID = Convert.ToInt32(m_command.ExecuteScalar());
                    }
                }
                m_command.CommandText = SupplierOutStandingInvoiceItem.DeleteUpdate(e.ID, e.EVENT_JOURNAL_ITEMS);
                m_command.ExecuteNonQuery();
                trc.Commit();
            }
            catch (Exception x)
            {
                trc.Rollback();
                throw x;
            }
        }
        public double GetPaid(int sijiID)
        {
            m_command.CommandText = SupplierOutStandingInvoiceItem.GetByPaidSQL(sijiID);
            double d = Convert.ToDouble(m_command.ExecuteScalar());

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

                SupplierOutStandingInvoice stk = (SupplierOutStandingInvoice)e;
                m_command.CommandText = stk.GetInsertSQL();
                m_command.ExecuteNonQuery();
                m_command.CommandText = SupplierOutStandingInvoice.SelectMaxIDSQL();
                stk.ID = Convert.ToInt32(m_command.ExecuteScalar());
                foreach (SupplierOutStandingInvoiceItem item in stk.EVENT_JOURNAL_ITEMS)
                {
                    m_command.CommandText = item.GetInsertSQL();
                    m_command.ExecuteNonQuery();
                    m_command.CommandText = SupplierOutStandingInvoiceItem.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;
            }
        }
        internal static SupplierOutStandingInvoiceItem FindSOIItemlistForPayment(MySql.Data.MySqlClient.MySqlCommand cmd, int supinvItemID)
        {
            cmd.CommandText = SupplierOutStandingInvoiceItem.GetByIDSQL(supinvItemID);
            MySql.Data.MySqlClient.MySqlDataReader r      = cmd.ExecuteReader();
            SupplierOutStandingInvoiceItem         result = SupplierOutStandingInvoiceItem.TransformReader(r);

            r.Close();
            cmd.CommandText = SupplierOutStandingInvoice.GetByIDSQL(result.EVENT_JOURNAL.ID);
            r = cmd.ExecuteReader();
            result.EVENT_JOURNAL = SupplierOutStandingInvoice.TransformReader(r);
            r.Close();

            cmd.CommandText = Currency.GetByIDSQLStatic(result.CURRENCY.ID);
            r = cmd.ExecuteReader();
            result.CURRENCY = Currency.GetCurrency(r);
            r.Close();

            cmd.CommandText = TermOfPayment.GetByIDSQLStatic(result.TOP.ID);
            r          = cmd.ExecuteReader();
            result.TOP = TermOfPayment.GetTOP(r);
            r.Close();

            cmd.CommandText = Employee.GetByIDSQLStatic(result.EMPLOYEE.ID);
            r = cmd.ExecuteReader();
            result.EMPLOYEE = Employee.GetEmployee(r);
            r.Close();


            return(result);
        }
        public static IList TransformReaderList(MySql.Data.MySqlClient.MySqlDataReader aReader)
        {
            IList result = new ArrayList();

            while (aReader.Read())
            {
                SupplierOutStandingInvoiceItem transaction = new SupplierOutStandingInvoiceItem();
                transaction.ID            = Convert.ToInt32(aReader["sostii_id"]);
                transaction.EVENT_JOURNAL = new SupplierOutStandingInvoice(Convert.ToInt32(aReader["sosti_id"]));
                transaction.VENDOR        = new Supplier(Convert.ToInt32(aReader["sup_id"]));
                transaction.CURRENCY      = new Currency(Convert.ToInt32(aReader["ccy_id"]));
                transaction.AMOUNT        = Convert.ToDouble(aReader["sostii_amount"]);
                //transaction.VENDOR_BALANCE_ENTRY = new VendorBalanceEntry(
                //VENDOR_BALANCE == null ? 0 : VENDOR_BALANCE.ID,
                transaction.VENDOR_BALANCE_ENTRY_TYPE = VendorBalanceEntryType.SupplierOutStandingInvoice;
                transaction.INVOICE_DATE           = Convert.ToDateTime(aReader["sostii_invoicedate"]);
                transaction.INVOICE_NO             = aReader["sostii_invoiceno"].ToString();
                transaction.DUE_DATE               = Convert.ToDateTime(aReader["sostii_duedate"]);
                transaction.EMPLOYEE               = new Employee(Convert.ToInt32(aReader["emp_id"]));
                transaction.DISCOUNT               = Convert.ToDouble(aReader["sostii_discount"]);
                transaction.AMOUNT_BEFORE_DISCOUNT = Convert.ToDouble(aReader["sostii_amountbeforediscount"]);
                transaction.TOP                    = new TermOfPayment(Convert.ToInt32(aReader["top_id"]));
                transaction.DESCRIPTION            = aReader["sostii_description"].ToString();
                transaction.NOTES                  = aReader["sostii_notes"].ToString();
                transaction.AGAINST_PAYMENT_STATUS = (AgainstStatus)Enum.Parse(typeof(AgainstStatus), aReader["sostii_againstpaymentstatus"].ToString());
                transaction.OUTSTANDING_AMOUNT     = Convert.ToDouble(aReader["sostii_outstandingamount"]);
                transaction.PAID_AMOUNT            = Convert.ToDouble(aReader["sostii_paidamount"]);
                result.Add(transaction);
            }
            return(result);
        }
        public static void UpdateAgainstStatus(MySql.Data.MySqlClient.MySqlCommand cmd, EventJournal e, ISupplierInvoiceJournalItem ei)
        {
            SupplierOutStandingInvoice     po  = (SupplierOutStandingInvoice)e;
            SupplierOutStandingInvoiceItem poi = (SupplierOutStandingInvoiceItem)ei;

            cmd.CommandText = poi.UpdateAgainstStatus();
            cmd.ExecuteNonQuery();
            cmd.CommandText = po.UpdateAgainstStatus();
            cmd.ExecuteNonQuery();
        }
Beispiel #7
0
        public void UpdateAgainstPaymentStatusSIJ()
        {
            bool allClosed = true;

            for (int i = 0; i < EVENT_JOURNAL_ITEMS.Count; i++)
            {
                SupplierOutStandingInvoiceItem poi = EVENT_JOURNAL_ITEMS[i] as SupplierOutStandingInvoiceItem;
                if (poi.AGAINST_PAYMENT_STATUS == AgainstStatus.Close)
                {
                    continue;
                }
                allClosed = false;
                break;
            }
            AGAINST_PAYMENT_STATUS = allClosed ? AgainstStatus.Close : AgainstStatus.Outstanding;
        }
        protected override void doDeleteNoTransaction(EventJournal e)
        {
            SupplierOutStandingInvoice st = (SupplierOutStandingInvoice)e;

            try
            {
                if (getEventStatus(st.ID) == EventStatus.Confirm)
                {
                    throw new Exception("Revise before delete");
                }
                m_command.CommandText = SupplierOutStandingInvoiceItem.DeleteAllByEventSQL(st.ID);
                m_command.ExecuteNonQuery();
                m_command.CommandText = SupplierOutStandingInvoice.DeleteSQL(st.ID);
                m_command.ExecuteNonQuery();
            }
            catch (Exception x)
            {
                throw x;
            }
        }
        public IList FindSOIJournalItemlistForPayment(string find, int ccyID, int supplier, DateTime trdate, IList notIn)
        {
            StringBuilder poisSB = new StringBuilder();

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

            pois = notIn.Count > 0 ? pois.Substring(0, pois.Length - 1) : "";
            m_command.CommandText = SupplierOutStandingInvoiceItem.GetSearchForPayment(find, ccyID, supplier, pois, trdate);
            MySql.Data.MySqlClient.MySqlDataReader r = m_command.ExecuteReader();
            IList result = SupplierOutStandingInvoiceItem.TransformReaderList(r);

            r.Close();
            foreach (SupplierOutStandingInvoiceItem t in result)
            {
                m_command.CommandText = SupplierOutStandingInvoice.GetByIDSQL(t.EVENT_JOURNAL.ID);
                r = m_command.ExecuteReader();
                t.EVENT_JOURNAL = SupplierOutStandingInvoice.TransformReader(r);
                r.Close();

                m_command.CommandText = Currency.GetByIDSQLStatic(t.CURRENCY.ID);
                r          = m_command.ExecuteReader();
                t.CURRENCY = Currency.GetCurrency(r);
                r.Close();

                m_command.CommandText = TermOfPayment.GetByIDSQLStatic(t.TOP.ID);
                r     = m_command.ExecuteReader();
                t.TOP = TermOfPayment.GetTOP(r);
                r.Close();

                m_command.CommandText = Employee.GetByIDSQLStatic(t.EMPLOYEE.ID);
                r          = m_command.ExecuteReader();
                t.EMPLOYEE = Employee.GetEmployee(r);
                r.Close();
            }
            return(result);
        }
        protected override EventJournal doGet(int ID)
        {
            m_command.CommandText = SupplierOutStandingInvoice.GetByIDSQL(ID);
            MySql.Data.MySqlClient.MySqlDataReader r  = m_command.ExecuteReader();
            SupplierOutStandingInvoice             st = SupplierOutStandingInvoice.TransformReader(r);

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

            r.Close();
            foreach (SupplierOutStandingInvoiceItem 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);
                st.EVENT_JOURNAL_ITEMS.Add(sti);
            }
            return(st);
        }
        protected override void doDelete(EventJournal e)
        {
            SupplierOutStandingInvoice st = (SupplierOutStandingInvoice)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 = SupplierOutStandingInvoiceItem.DeleteAllByEventSQL(st.ID);
                m_command.ExecuteNonQuery();
                m_command.CommandText = SupplierOutStandingInvoice.DeleteSQL(st.ID);
                m_command.ExecuteNonQuery();
                trc.Commit();
            }
            catch (Exception x)
            {
                trc.Rollback();
                throw x;
            }
        }