Example #1
0
        public static IList TransformReaderList(MySql.Data.MySqlClient.MySqlDataReader aReader)
        {
            IList result = new ArrayList();

            while (aReader.Read())
            {
                APDebitNoteItem transaction = new APDebitNoteItem();
                transaction.ID            = Convert.ToInt32(aReader["apdni_id"]);
                transaction.EVENT_JOURNAL = new APDebitNote(Convert.ToInt32(aReader["apdn_id"]));
                transaction.VENDOR        = new Supplier(Convert.ToInt32(aReader["sup_id"]));
                transaction.CURRENCY      = new Currency(Convert.ToInt32(aReader["ccy_id"]));
                transaction.AMOUNT        = Convert.ToDouble(aReader["apdni_amount"]);
                //transaction.VENDOR_BALANCE_ENTRY = new VendorBalanceEntry(
                //VENDOR_BALANCE == null ? 0 : VENDOR_BALANCE.ID,
                transaction.VENDOR_BALANCE_ENTRY_TYPE = VendorBalanceEntryType.APDebitNote;
                transaction.INVOICE_DATE           = Convert.ToDateTime(aReader["apdni_invoicedate"]);
                transaction.INVOICE_NO             = aReader["apdni_invoiceno"].ToString();
                transaction.DUE_DATE               = Convert.ToDateTime(aReader["apdni_duedate"]);
                transaction.EMPLOYEE               = new Employee(Convert.ToInt32(aReader["emp_id"]));
                transaction.DISCOUNT               = Convert.ToDouble(aReader["apdni_discount"]);
                transaction.AMOUNT_BEFORE_DISCOUNT = Convert.ToDouble(aReader["apdni_amountbeforediscount"]);
                transaction.TOP             = new TermOfPayment(Convert.ToInt32(aReader["top_id"]));
                transaction.DESCRIPTION     = aReader["apdni_description"].ToString();
                transaction.NOTES           = aReader["apdni_notes"].ToString();
                transaction.PURCHASE_RETURN = new PurchaseReturn(Convert.ToInt32(aReader["prn_id"]));
                result.Add(transaction);
            }
            return(result);
        }
Example #2
0
        protected override void doDelete(Event e)
        {
            PurchaseReturn st = (PurchaseReturn)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 = APDebitNoteItem.GetPRUsedByAPDN(st.ID);
                int count = Convert.ToInt32(m_command.ExecuteScalar());
                if (count > 0)
                {
                    throw new Exception("Can not delete this Purchase Return, this Purchase Return used by APDN");
                }

                m_command.CommandText = PurchaseReturnItem.DeleteAllByEventSQL(st.ID);
                m_command.ExecuteNonQuery();
                m_command.CommandText = PurchaseReturn.DeleteSQL(st.ID);
                m_command.ExecuteNonQuery();
                trc.Commit();
            }
            catch (Exception x)
            {
                trc.Rollback();
                throw x;
            }
        }
Example #3
0
        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;
            }
        }
Example #4
0
        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;
            }
        }
Example #5
0
        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;
            }
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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;
            }
        }
Example #9
0
        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;
            }
        }
Example #10
0
        public IList FindPRForAPDebitNote(string find, int supID, DateTime trdate, IList added)
        {
            m_command.CommandText = APDebitNoteItem.GetPRUsedByAPDN();
            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 = PurchaseReturn.GetSearchPRNoForAPDN(find, supID, pois, trdate);
            r = m_command.ExecuteReader();
            IList result = PurchaseReturn.TransformReaderList(r);

            r.Close();
            foreach (PurchaseReturn p in result)
            {
                m_command.CommandText = PurchaseReturnItem.GetByEventIDSQL(p.ID);
                r             = m_command.ExecuteReader();
                p.EVENT_ITEMS = PurchaseReturnItem.TransformReaderList(r);
                r.Close();

                foreach (PurchaseReturnItem t in p.EVENT_ITEMS)
                {
                    if ((t.GRN_ITEM == null) && (t.GRN_ITEM.ID == 0))
                    {
                        continue;
                    }


                    m_command.CommandText = GoodReceiveNoteItem.GetByIDSQL(t.GRN_ITEM.ID);
                    r          = m_command.ExecuteReader();
                    t.GRN_ITEM = GoodReceiveNoteItem.TransformReader(r);
                    r.Close();

                    if ((t.GRN_ITEM.PO_ITEM == null))
                    {
                        continue;
                    }
                    if (t.GRN_ITEM.PO_ITEM.ID == 0)
                    {
                        continue;
                    }

                    m_command.CommandText = PurchaseOrderItem.GetByIDSQL(t.GRN_ITEM.PO_ITEM.ID);
                    r = m_command.ExecuteReader();
                    t.GRN_ITEM.PO_ITEM = PurchaseOrderItem.TransformReader(r);
                    r.Close();

                    t.GRN_ITEM.PART = PartRepository.GetByID(m_command, t.GRN_ITEM.PART.ID);
                    t.GRN_ITEM.PART.UNIT_CONVERSION_LIST = PartRepository.GetUnitConversionsStatic(m_command, t.GRN_ITEM.PO_ITEM.PART.ID);
                    t.PART = t.GRN_ITEM.PO_ITEM.PART = t.GRN_ITEM.PART;

                    double subamount = (t.GRN_ITEM.PO_ITEM.SUBTOTAL / t.GRN_ITEM.PO_ITEM.GetAmountInSmallestUnit()) * t.GetAmountInSmallestUnit();
                    p.TOTAL_AMOUNT_FROM_PO += subamount;

                    t.GRN_ITEM.PO_ITEM.EVENT = PurchaseOrderRepository.GetHeaderOnly(m_command, t.GRN_ITEM.PO_ITEM.EVENT.ID);
                    p.CURRENCY = ((PurchaseOrder)t.GRN_ITEM.PO_ITEM.EVENT).CURRENCY;
                }
            }
            return(result);
        }