Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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);
        }