public FormVIEWAGENT(FINANCE.FormTAGIHAN _frm, RMS.COMMON.MASTER.RMS_SUPPLIER obj, int _type)
 {
     InitializeComponent();
     type = _type;
     if (type == 1)
     {
         this.frm = _frm;
         c = obj;
     }
     LOAD_DATA();
     this.txtCARI.Focus();
 }
        public FormTAGIHAN(FINANCE.FormDAFTARPEMBAYARANHUTANG _frm, int _Type, RMS.COMMON.DELIVERYORDER.RMS_TAGIHAN obj)
        {
            InitializeComponent();
            this.frm = _frm;
            this.Type = _Type;
            //txtKODE.Text = GETKODE();
            //txtKODE.ReadOnly = true;
            if (Type == 1)
            {

                LOAD_DATA(obj);
            }
        }
        public FormPEMBAYARANTAGIHAN(FINANCE.FormDAFTARPEMBAYARANHUTANG _frm, int Type, RMS.COMMON.DELIVERYORDER.RMS_TAGIHAN obj)
        {
            InitializeComponent();
            this.type = Type;
            type = 0;
            c.ID = obj.ID;
            cPMB.IDTAGIHAN = obj.ID;
            //cDETAIL.KODEIVOICE = obj.KODEINVOICE;

            cboMETODEBAYAR.Text = "CASH";
            cboJENISBAYAR.Text = "PELUNASAN";
            pnlNOTRANSFER.Visible = false;
            if (type == 0)
            {
                LOAD_DATA(obj);
                LOAD_HISTORYBAYAR(c);

            }
        }
        public FormPEMBAYARAN(FINANCE.FormDAFTARPEMBAYRANPIUTANG _frm, int Type, RMS.COMMON.DELIVERYORDER.RMS_DETAILINVOICE obj)
        {
            InitializeComponent();
            this.frm = _frm;
            this.Type = Type;
            type = 0;

            cPMB.IDSTT = obj.ID;
            c.ID = obj.ID;
            cboMETODEBAYAR.Text = "CASH";
            cboJENISBAYAR.Text = "PELUNASAN";
            pnlNOTRANSFER.Visible = false;
            txtTERBILANG.Visible = false;
            if (type == 0)
            {
                LOAD_DATA(obj);
                LOAD_HISTORYBAYAR(cPMB);

            }
        }
        private void DeleteAssetFinance(string assno)
        {
            using (AccetManagementEntities db = new AccetManagementEntities())
            {
                FINANCE aFinance = new FINANCE();
                //var assFinance = db.FINANCEs.SingleOrDefault(x => x.ASSETNO == assno);
                aFinance = db.FINANCEs.SingleOrDefault(x => x.ASSETNO == assno);
                //db.ASSETIMAGEs.Where(x => x.ASSETID == assno).FirstOrDefault();

                if (aFinance != null)
                {
                    var entry = db.Entry(aFinance);

                    if (entry.State == EntityState.Unchanged)
                    {
                        db.FINANCEs.Attach(aFinance);
                        db.FINANCEs.Remove(aFinance);
                        db.SaveChanges();
                    }
                }
            }
        }
        internal void GetControls(string assno)
        {
            var idVendor = "";
            using (AccetManagementEntities db = new AccetManagementEntities())
            {
                //var currentConditionId = db.CONDITIONs.Where(c => c.CONDITIONNAME == r).OrderBy(c => c.CONDITIONID).Select(c => c.CONDITIONID).ToList();
                if (Finances.VendorName != null)
                {
                    var vendorId = db.VENDORs
                                        .Where(e => e.VENDORNAME == Finances.VendorName)
                                        .Select(e => e.VENDORNO).ToList();
                    idVendor = vendorId[0].ToString();

                }
                if (Finances.PurchasePrice == null)
                {
                    Finances.PurchasePrice = "0";
                }
                if (Finances.MarketVlaue ==null)
                {
                    Finances.MarketVlaue = "0";
                }

                if (Finances.ScrapValue == null)
                {
                    Finances.ScrapValue = "0";
                }
                if (Finances.TxtPoNumber == null)
                {
                    Finances.TxtPoNumber = "0";
                }

                if (Finances.DatePurchase == null || Finances.DatePurchase == "")
                {
                    Finances.DatePurchase =Convert.ToString( DateTime.Now);
                }
                if (Finances.Service == null || Finances.Service == "")
                {
                    Finances.Service = Convert.ToString(DateTime.Now);
                }
                if (Finances.DtpWarranty == null || Finances.DtpWarranty == "")
                {
                    Finances.DtpWarranty = Convert.ToString(DateTime.Now);
                }

                //var depreciationId = db.Depreciations.Where(d => d.DepresiationName == cmdDepreciation.Text).
                //                                        Select(d => d.ID).ToList();

                var financeTableData = db.FINANCEs.SingleOrDefault(c => c.ASSETNO == assno);

                if (financeTableData == null)
                {

                        FINANCE fINANCE = new FINANCE
                        {

                            ASSETNO = assno,
                            VENDORNO = idVendor,
                            PONO = Finances.TxtPoNumber,
                            PURCHASEPRICE = Convert.ToDecimal(Finances.PurchasePrice),
                            MARKETVALUE = Convert.ToDecimal(Finances.MarketVlaue),
                            SCRAPEVALUE = Convert.ToDecimal(Finances.ScrapValue),
                            DEPRECIATIONID = 1,
                            PURCHASEDATE = Convert.ToDateTime(Finances.DatePurchase),
                            INSERVICEDATE = Convert.ToDateTime(Finances.Service),
                            WARRANTYEND = Convert.ToDateTime(Finances.DtpWarranty)
                        };
                        db.FINANCEs.Add(fINANCE);

                }
                else
                {
                    financeTableData.ASSETNO = assno;
                    financeTableData.DEPRECIATIONID = 1;
                    financeTableData.INSERVICEDATE = Convert.ToDateTime(Finances.Service);
                    financeTableData.MARKETVALUE = Convert.ToDecimal(Finances.MarketVlaue);
                    financeTableData.PONO = Finances.TxtPoNumber;
                    financeTableData.PURCHASEDATE = Convert.ToDateTime(Finances.DatePurchase);
                    financeTableData.PURCHASEPRICE = Convert.ToDecimal(Finances.PurchasePrice);
                    financeTableData.RECOVERYPERIOD = Convert.ToInt32(Finances.RecPeriod);
                    financeTableData.SCRAPEVALUE = Convert.ToDecimal(Finances.ScrapValue);
                    financeTableData.VENDORNO = idVendor;
                    financeTableData.WARRANTYEND = Convert.ToDateTime(Finances.DtpWarranty);
                }

                db.SaveChanges();

            }
        }