Exemplo n.º 1
0
        public int InsertPO(POHeaderModel model)
        {
            model.CreationDate   = DateTime.Now;
            model.LastUpdateDate = DateTime.Now;

            return(factory.POHeaderDao.Insert(model));
        }
Exemplo n.º 2
0
        public void Delete(POHeaderModel model)
        {
            string sql = @"DELETE FROM po_headers_all WHERE po_header_id = @po_header_id";

            object[] parms = { "@po_header_id", model.PoHeaderId };
            db.Update(sql, parms);
        }
Exemplo n.º 3
0
        private void Selecting_Row(object sender, EventArgs e)
        {
            MetroGrid grid = sender as MetroGrid;

            if (grid.SelectedRows.Count > 0)
            {
                List <POHeaderModel> pos = new List <POHeaderModel>(); // grid.SelectedRows.DataBoundItem;
                foreach (DataGridViewRow item in grid.SelectedRows)
                {
                    try
                    {
                        int           id = Convert.ToInt32(item.Cells[0].Value);
                        POHeaderModel po = _view.list.Where(x => x.PoHeaderId == id).FirstOrDefault();
                        pos.Add(po);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                if (pos.Count != 0)
                {
                    _view.posSelected = pos;
                }
            }
        }
Exemplo n.º 4
0
        // GET: POReceipt/Details/5
        public ActionResult Details(int id)
        {
            entity = (POHeaderModel)TempData["POHeaderModel"];
            PODetailModel objPODtl = entity?.PODetails?.Where(w => w.POLine == id).SingleOrDefault();

            return(View(objPODtl));
        }
Exemplo n.º 5
0
        private void SearchPO_Click(object sender, EventArgs e)
        {
            POHeaderModel po = null;

            if (!string.IsNullOrEmpty(_view.poNumber))
            {
                po = _repository.GetPOByNumber(_view.poNumber);
            }

            if (po != null)
            {
                _view.po = po;
                GetPOLines();
            }
            else
            {
                using (POListForm frm = new POListForm(null))
                {
                    frm.vendorId = _view.vendorId;
                    //frm.poNum = _view.poNumber;
                    frm.startDate = DateTime.Now.AddDays(-5);
                    frm.ShowDialog();
                    if (frm.posSelected != null)
                    {
                        _view.po = frm.posSelected.FirstOrDefault();
                        GetPOLines();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public ActionResult PrintTag(LotAttributeModel lotAttributeModel)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            POHeaderModel entity = (POHeaderModel)Session["ModifiedPOHeaderModel"];

            entity.PODetails.ForEach(s => s.LotAttribute = lotAttributeModel);

            Session["ModifiedPOHeaderModel"] = entity;
            //TempData.Keep("ModifiedPOHeaderModel");
            ViewBag.Uom     = entity.PODetails.Select(s => s.UomCode).FirstOrDefault <string>();
            ViewBag.UserQty = entity.PODetails.Select(s => s.Qty).FirstOrDefault <decimal>();

            PrintTagModel objPrintTag = new PrintTagModel();

            if (!entity.CartonLabel)
            {
                return(RedirectToAction("ManualUpdate", objPrintTag));
            }

            objPrintTag.Id      = lotAttributeModel.Id;
            objPrintTag.Company = lotAttributeModel.Company;
            objPrintTag.PONum   = lotAttributeModel.PONum;
            objPrintTag.POLine  = lotAttributeModel.POLine;
            objPrintTag.DONum   = lotAttributeModel.DONum;
            objPrintTag.PartNum = lotAttributeModel.PartNum;
            objPrintTag.LotNum  = lotAttributeModel.LotNum;

            return(View(objPrintTag));
        }
 public async Task <IList <POAprovalModel> > FindPOAprovalAsync(POHeaderModel pr)
 {
     using (var db = HibernateSession.GetCurrentSession()) {
         using (var tx = db.BeginTransaction()) {
             return(db.QueryOver <POAprovalModel>().Where(x => x.POHeader == pr).List());
         }
     }
 }
Exemplo n.º 8
0
        public ActionResult ManualUpdate(PrintTagModel obj)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            string errMsg = "";
            string msg    = "-";

            POHeaderModel entity = (POHeaderModel)Session["ModifiedPOHeaderModel"];

            TempData["PONum"]   = entity.PONum;
            TempData["DONum"]   = entity.DONum;
            TempData["Company"] = entity.Company;

            entity.PODetails.ForEach(s => s.PrintTag = obj);

            HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("POReceipt", entity).Result;

            //TempData["RespondMessage"] = response.Content.ReadAsStringAsync().Result;

            if (response.IsSuccessStatusCode)
            {
                errMsg = "";
            }
            else
            {
                msg = response.Content.ReadAsStringAsync().Result;
                try
                {
                    JObject jObject = JObject.Parse(msg);
                    string  msgJ    = (string)jObject.SelectToken("Message");
                    string  msgDtl  = (string)jObject.SelectToken("MessageDetail");
                    if (msgDtl == null)
                    {
                        errMsg = msgJ;
                    }
                    else
                    {
                        errMsg = msgDtl;
                    }
                }
                catch (Exception ex)
                {
                    errMsg = msg;
                }
            }

            ViewBag.Status  = errMsg;
            ViewBag.PONum   = entity.PONum;
            ViewBag.DONum   = entity.DONum;
            ViewBag.Company = entity.Company;
            return(View());

            // return Json(new { Message = msg }, JsonRequestBehavior.AllowGet);
        }
        private void GeneratePOLocation(IEnumerable <POReceiptLineModel> lines)
        {
            //POReceiptHeaderModel recHead = _view.headSeleted;
            IEnumerable <POReceiptLineModel> resultLines = lines;

            if (_view.headSeleted.ReceiptMethod == "RETURN")
            {
                resultLines = lines.Where(x => x.QuantityShipped < 0).ToList();
            }

            foreach (var recLine in resultLines)
            {
                POLineLocationModel loc = new POLineLocationModel();
                loc.PoHeaderId             = recLine.PoHeaderId;
                loc.PoLineId               = recLine.PoLineId;
                loc.Quantity               = recLine.QuantityShipped;
                loc.QuantityReceived       = recLine.QuantityShipped;
                loc.UnitMeasLookupCode     = recLine.UnitOfMeasure;
                loc.InspectionRequiredFlag = recLine.QcRequireInspcFlag;
                loc.ReceiptHeaderId        = recLine.ReceiptHeaderId;
                loc.ReceiptLineId          = recLine.ReceiptLineId;
                loc.ConfirmFlag            = "N";

                int id = _repoPurchase.InsertPoLineLocation(loc);
            }

            //Get PO Lines to Update PO Status ***Not support multi PO in same Receive.
            int poId = lines.FirstOrDefault().PoHeaderId;
            List <POLineModel> poLines = _repoPurchase.GetPOLineByPOID(poId);

            var result = poLines.GroupBy(x => x.ReceivedStatus)
                         .Select(group => new { ReceivedStatus = group.Key, Items = group.ToList() })
                         .ToList();

            POHeaderModel po = _repoPurchase.GetPOByID(poId);

            if (result.Count() == 1)
            {
                if (result.FirstOrDefault().ReceivedStatus == "Fill")
                {
                    po.StatusCode   = "FINALLY CLOSED";
                    po.ReceivedFlag = true;
                }
                else
                {
                    po.StatusCode   = "OPEN";
                    po.ReceivedFlag = false;
                }
            }
            else
            {
                po.StatusCode   = "OPEN";
                po.ReceivedFlag = false;
            }
            _repoPurchase.UpdatePO(po);
        }
Exemplo n.º 10
0
        // GET: POReceipt


        public ActionResult Index(string searchBy, string search, string company)
        {
            entity = new POHeaderModel();
            if (!string.IsNullOrEmpty(search))
            {
                string Qry = $"POReceipt?{searchBy}={search}&Company={company}";
                HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync(Qry).Result;
                entity = response.Content.ReadAsAsync <POHeaderModel>().Result;
                TempData["POHeaderModel"] = entity;
            }
            return(View(entity));
        }
        private POHeaderModel CombindVendor(POHeaderModel head)
        {
            POHeaderModel po     = head;
            VendorModel   vendor = _repoPay.GetVendorByID(po.VendorId);

            #region Setup Vendor
            if (vendor != null)
            {
                po.VendorNum  = vendor.VendorNumber;
                po.VendorName = vendor.VendorName;

                //Default Term by Vendor
                if (!string.IsNullOrEmpty(vendor.TermCode))
                {
                    TermModel term = _repoPay.GetTermByCode(vendor.TermCode);
                    if (term != null)
                    {
                        po.TermId   = term.TermId;
                        po.TermCode = term.TermCode;
                        po.TermDesc = term.Description;
                    }
                }

                //Default Term by Currency
                if (!string.IsNullOrEmpty(vendor.InvoiceCurrencyCode))
                {
                    CurrencyModel curr = _repoPO.GetToCurrencyByCode(vendor.InvoiceCurrencyCode);
                    if (curr != null)
                    {
                        po.CurrencyCode = vendor.InvoiceCurrencyCode;
                        //po.Rate = curr.ConversionRate == 0 ? 1 : curr.ConversionRate;
                        //po.RateDate = curr.ConversionDate;
                    }
                }

                //Default Term by Tax
                if (!string.IsNullOrEmpty(vendor.VatCode))
                {
                    TaxCodeModel tax = _repoPO.GetTaxCodes().Where(x => x.TaxCode == vendor.VatCode).FirstOrDefault();
                    if (tax != null)
                    {
                        po.TaxCode = tax.TaxCode;
                        po.TaxRate = tax.TaxRate;
                    }
                }
            }
            #endregion

            return(po);
        }
Exemplo n.º 12
0
 private object[] Take(POHeaderModel model)
 {
     return(new object[]
     {
         "@po_header_id", model.PoHeaderId,
         "@po_num", model.PoNum,
         "@po_date", model.PODate,
         "@type_lookup_code", model.TypeLookupCode,
         "@vendor_id", model.VendorId,
         "@vendor_site_id", model.VendorSiteId,
         "@vendor_num", model.VendorNum,
         "@ship_to_location_id", model.ShipToLocationId,
         "@bill_to_location_id", model.BillToLocationId,
         "@term_id", model.TermId,
         "@term_code", model.TermCode,
         "@currency_code", model.CurrencyCode,
         "@rate_type", model.RateType,
         "@rate_date", model.RateDate,
         "@rate", model.Rate,
         "@authorization_status", model.AuthorizationStatus,
         "@revision_num", model.RevisionNum,
         "@revised_date", model.RevisedDate,
         "@approved_flag", (model.ApprovedFlag) ? "Y" : "N",
         "@approved_date", model.ApprovedDate,
         "@remarks", model.Remarks,
         "@closed_date", model.ClosedDate,
         "@approval_required_flag", model.ApprovalRequiredFlag,
         "@cancel_flag", (model.CancelFlag) ? "Y" : "N",
         "@status_code", model.StatusCode,
         "@tax_code", model.TaxCode,
         "@tax_rate", model.TaxRate,
         "@sub_total", model.SubTotal,
         "@tax_amount", model.TaxAmount,
         "@discount", model.Discount,
         "@freight", model.Freight,
         "@total_amount", model.TotalAmount,
         "@status", model.Status,
         "@last_update_date", model.LastUpdateDate,
         "@last_updated_by", model.LastUpdatedBy,
         "@creation_date", model.CreationDate,
         "@created_by", model.CreatedBy,
         "@received_flag", (model.ReceivedFlag) ? "Y" : "N",
         "@buyer_id", model.BuyerId,
         "@submit_flag", (model.SubmitFlag) ? "Y" : "N",
         "@job_flag", (model.JobFlag) ? "Y" : "N",
         "@revision_notes", model.RevisionNote,
         "@approver_id", model.ApproverId
     });
 }
 public async Task SaveOrUpdatePOHeaderAsync(POHeaderModel header)
 {
     using (var db = HibernateSession.GetCurrentSession()) {
         using (var tx = db.BeginTransaction()) {
             db.SaveOrUpdate(header);
             var poa = new PRAccessor();
             if (header.RequisitionNo == null)
             {
                 header.RequisitionNo = poa.GetRequisitionNo(header.Requestor, header.Id);
                 db.Update(header);
             }
             tx.Commit();
             db.Flush();
         }
     }
 }
Exemplo n.º 14
0
        public void Update(POHeaderModel model)
        {
            string sql =
                @"UPDATE po_headers_all
                   SET po_num = @po_num
                      ,po_date = @po_date
                      ,type_lookup_code = @type_lookup_code
                      ,last_update_date = @last_update_date
                      ,last_updated_by = @last_updated_by
                      ,vendor_id = @vendor_id
                      ,vendor_site_id = @vendor_site_id
                      ,vendor_num = @vendor_num
                      ,ship_to_location_id = @ship_to_location_id
                      ,bill_to_location_id = @bill_to_location_id
                      ,term_id = @term_id
                      ,term_code = @term_code
                      ,currency_code = @currency_code
                      ,rate_type = @rate_type
                      ,rate_date = @rate_date
                      ,rate = @rate
                      ,authorization_status = @authorization_status
                      ,revision_num = @revision_num
                      ,revised_date = @revised_date
                      ,approved_flag = @approved_flag
                      ,approved_date = @approved_date
                      ,remarks = @remarks
                      ,closed_date = @closed_date
                      ,approval_required_flag = @approval_required_flag
                      ,cancel_flag = @cancel_flag
                      ,status_code = @status_code
                      ,tax_code = @tax_code
                      ,tax_rate = @tax_rate
                      ,sub_total = @sub_total
                      ,tax_amount = @tax_amount
                      ,discount = @discount
                      ,freight = @freight
                      ,total_amount = @total_amount
                      ,status = @status
                      ,submit_flag = @submit_flag
                      ,job_flag = @job_flag
                      ,received_flag = @received_flag
                      ,revision_notes = @revision_notes
                      ,approver_id = @approver_id
                 WHERE po_header_id = @po_header_id";

            db.Update(sql, Take(model));
        }
        public async Task <IList <POHeaderModel> > SearchPRAsync(string search)
        {
            using (var db = HibernateSession.GetCurrentSession()) {
                using (var tx = db.BeginTransaction()) {
                    POHeaderModel   po    = null;
                    EmployeeModel   emp   = null;
                    DepartmentModel dep   = null;
                    var             items = db.QueryOver <POHeaderModel>(() => po)
                                            .JoinAlias(() => po.Requestor, () => emp)
                                            .JoinAlias(() => emp.Department, () => dep)
                                            .Where(x => po.DeleteTime == null && (po.RequisitionNo.IsLike("%" + search + "%") ||
                                                                                  emp.LastName.IsLike(search + "%") ||
                                                                                  dep.Name.IsLike(search + "%"))).OrderBy(() => po.CreateTime).Desc.Take(10);

                    return(items.List());
                }
            }
        }
Exemplo n.º 16
0
        public POEntryForm(POHeaderModel po)
        {
            InitializeComponent();
            this.Size  = Screen.PrimaryScreen.WorkingArea.Size;
            _presenter = new POEntryPresenter(this);

            bindingLine = new BindingSource();

            this.dgvLine.RowPrePaint
                += new System.Windows.Forms.DataGridViewRowPrePaintEventHandler(
                       this.dgvLine_RowPrePaint);

            this.dgvBudget.RowPrePaint
                += new System.Windows.Forms.DataGridViewRowPrePaintEventHandler(
                       this.dgvBudget_RowPrePaint);

            if (po != null)
            {
                poHead = po;
            }
        }
Exemplo n.º 17
0
        //int poDetailId;
        // GET: POReceipt

        public ActionResult Index(string PONum, string Company)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            if (Session["Company"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            //Session["XOrderQty"] = null;

            Company = (string)Session["Company"];

            POHeaderModel entity = new POHeaderModel();

            if (!string.IsNullOrEmpty(Company) && !string.IsNullOrEmpty(PONum))
            {
                string Qry = $"POReceipt?PONum={PONum}&Company={Company}"; //Ashraf
                HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync(Qry).Result;
                if (response.IsSuccessStatusCode)
                {
                    entity = response.Content.ReadAsAsync <POHeaderModel>().Result;
                    if (Request.QueryString["DONum"] != null)
                    {
                        entity.DONum = Request.QueryString["DONum"].ToString();
                    }
                    Session["POHeaderModel"] = entity;
                }
                else
                {
                    var httpErr = response.Content.ReadAsAsync <errHttpAmin.HttpError>();
                    ViewBag.Error = httpErr.Result["Message"].ToString();
                }
            }

            return(View(entity));
        }
Exemplo n.º 18
0
        // GET: POReceipt/Details/5
        public ActionResult Details(int id)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (Session["Company"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            //Session["XOrderQty"] = null;

            POHeaderModel entity = (POHeaderModel)Session["POHeaderModel"];

            //Session["POHeaderModel"] = entity;
            if (Request.QueryString["DONum"] != null)
            {
                entity.DONum = Request.QueryString["DONum"].ToString();
            }

            Session["PONum"]   = entity.PONum;
            Session["DONum"]   = entity.DONum;
            Session["Company"] = entity.Company;

            //TempData.Keep("POHeaderModel");

            PODetailModel objPODtl = entity?.PODetails?.Where(w => w.POLine == id).SingleOrDefault();

            objPODtl.POInfo  = $"{objPODtl.PONum}/{objPODtl.POLine}";
            objPODtl.SuppNum = entity.SuppNum;
            objPODtl.DONum   = entity.DONum;

            entity.PODetails = new List <PODetailModel>();
            entity.PODetails.Add(objPODtl);

            return(View(objPODtl));
        }
        private void ConvertPO_Click(object sender, EventArgs e)
        {
            //_view.RefreshLinesGird();
            bool   jobProcess = false;
            int    vendorId   = 0;
            string poTypeCode = string.Empty;

            if (_view.linesSelected.Count == 0)
            {
                return;
            }

            var reqLines = _view.linesSelected;

            //Validation multiple Vendors
            var resVendors = reqLines.GroupBy(x => x.VendorId)
                             .Select(group => new { Vendor = group.Key, lines = group.ToList() })
                             .ToList();

            if (resVendors.Count > 1)
            {
                MessageBox.Show("Lines seleted more than one Vendors, cannot convert PO to one by one.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                vendorId = resVendors.FirstOrDefault().Vendor;
            }

            //Validation multiple Line Type
            var resTypes = reqLines.GroupBy(x => x.LineType)
                           .Select(group => new { LineType = group.Key, lines = group.ToList() })
                           .ToList();

            if (resTypes.Count > 1)
            {
                MessageBox.Show("Lines seleted more than one Type, cannot convert PO to one by one.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else
            {
                //Set PO Type Code.
                poTypeCode = resTypes.FirstOrDefault().LineType;

                var costs = _repoProj.GetCostGropAll();
                var str   = (from c in _view.linesSelected
                             select new { costCode = c.CostCode }).ToArray();

                var query = costs.Where(x => str.Any(a => a.costCode == x.CostCode)).ToList()
                            .GroupBy(p => p.MakingFlag)
                            .Select(group => new { makings = group.Key, glines = group.ToList() })
                            .ToList();
                if (query.Count > 1)
                {
                    MessageBox.Show("Lines seleted more than one Type, cannot convert PO to one by one.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    //Set PO Job Process Flag.
                    jobProcess = query.ToList().FirstOrDefault().makings;
                }
                //var jobProcessCosts = costs.Where(x => costs)
            }

            var resUnConfirm = reqLines.Where(x => !x.FinalConfirmFlag).ToList();

            if (resUnConfirm.Count > 0)
            {
                MessageBox.Show("Some lines seleted is not Confirm price.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            POHeaderModel head = new POHeaderModel();

            head.ProjectId      = _view.projectParam.Id;
            head.ProjectNum     = _view.projectParam.ProjectNum;
            head.JobFlag        = jobProcess;
            head.TypeLookupCode = poTypeCode;
            head.VendorId       = vendorId;
            head.PODate         = DateTime.Now;
            head.Status         = "OPEN";
            head.StatusCode     = "OPEN";
            head.BuyerId        = _view.EpiSession.User.Id;
            head.BuyerName      = _view.EpiSession.User.UserName;

            string typeLookup = string.Empty;

            if (head.TypeLookupCode == "STANDARD")
            {
                typeLookup = "PURCHASE_PO";
            }
            else if (head.TypeLookupCode == "MAKING")
            {
                if (head.JobFlag)
                {
                    typeLookup = "PURCHASE_PD";
                }
                else
                {
                    typeLookup = "PURCHASE_PO";
                }
            }
            //Combind Vendor Detail.
            head = CombindVendor(head);

            head.SubTotal   = _view.linesSelected.Sum(x => x.ExtendedAmount);
            head.PoNum      = _repoPO.GetDocNoByType(typeLookup);
            head.PoHeaderId = _repoPO.InsertPO(head);

            //Validate to Add Line
            if (head.PoHeaderId != 0)
            {
                try
                {
                    if (_view.linesSelected != null)
                    {
                        //List<POLineModel> list = _view.poLine;
                        foreach (RequisitionLineModel item in _view.linesSelected)
                        {
                            POLineModel pol = new POLineModel();
                            pol.PoHeaderId      = head.PoHeaderId;
                            pol.LastUpdatedBy   = _view.EpiSession.User.Id;
                            pol.CreatedBy       = _view.EpiSession.User.Id;
                            pol.RefProjectId    = _view.projectParam.Id;
                            pol.RefProjectNum   = _view.projectParam.ProjectNum;
                            pol.LastUpdateDate  = DateTime.Now;
                            pol.CreationDate    = DateTime.Now;
                            pol.Status          = "OPEN";
                            pol.BalloonNo       = item.BalloonNo;
                            pol.ItemCode        = item.ItemCode;
                            pol.Quantity        = item.Quantity;
                            pol.ItemDescription = item.ItemDescription;
                            pol.Spec            = item.SpecModel;
                            pol.BrandMaterail   = item.BrandMaterail;
                            pol.CostCode        = item.CostCode;
                            pol.BOM             = item.BomNo;
                            pol.Suplier         = item.SuplierSymbol;
                            pol.UnitPrice       = item.FinalUnitPrice;
                            pol.DueDate         = item.DueDate;
                            pol.ECN             = item.EcnNo;
                            pol.CSR             = item.CsrNo;
                            pol.Uom             = item.Uom;
                            pol.LeadTime        = item.LeadTime;
                            pol.LoadBomDate     = item.LoadBomDate;

                            int lineId = _repoPO.InsertPOLine(pol);
                            if (lineId != 0)
                            {
                                item.PurchasedFlag     = true;
                                item.PurchasedQuantity = item.Quantity;
                                item.PoLineId          = lineId;
                                item.PoHeaderId        = head.PoHeaderId;
                                _repository.UpdatePRLine(item);
                            }
                        }

                        //Update Purchased flag in Requisition Header
                        var grpHeads = _view.linesSelected.GroupBy(item => item.RequisitionHeaderId)
                                       .Select(group => new { reqHeaderId = group.Key, ReqLines = group.ToList() })
                                       .ToList();
                        foreach (var req in grpHeads)
                        {
                            _repository.UpdatePurchasedFlag(req.reqHeaderId);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("PO Lines is Error! " + Environment.NewLine
                                    + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Filter(null, null);
                MessageBox.Show(string.Format("Convert to PO Number : {0} complete.", head.PoNum), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                POEntryForm POfrm = new POEntryForm(head);
                POfrm.Show();
            }
        }
Exemplo n.º 20
0
        public ActionResult LotAttribute(PODetailModel obj)
        {
            if (Session["User"] == null || obj == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            //Session["XOrderQty"] = obj.XOrdQty; //bring XOrder Calc to Print Tag Page


            Session["LotNum"] = obj.LotNum;

            //if (TempData["ModifiedPODetailModel"] == obj) {

            //}

            POHeaderModel entity = (POHeaderModel)Session["POHeaderModel"];
            //This is for LotAttribute only
            PODetailModel objPODtl = new PODetailModel();

            objPODtl = entity.PODetails.Where(w => w.POLine == obj.POLine).SingleOrDefault();

            Session["LotNum"]  = objPODtl.LotNum;
            Session["PartNum"] = objPODtl.PartNum;

            //entity.PODetails = new List<PODetailModel>();
            //entity.PODetails.Add(obj );
            entity.PODetails.Where(w => w.POLine == obj.POLine).ToList().ForEach(s => s.TuId   = obj.TuId);
            entity.PODetails.Where(w => w.POLine == obj.POLine).ToList().ForEach(s => s.LotNum = obj.LotNum);
            entity.PODetails.Where(w => w.POLine == obj.POLine).ToList().ForEach(s => s.Qty    = obj.Qty);
            entity.PODetails.Where(w => w.POLine == obj.POLine).ToList().ForEach(s => s.TuConv = obj.TuConv);

            Session["ModifiedPOHeaderModel"] = entity;
            //TempData.Keep("ModifiedPOHeaderModel");

            //Lot Validation (is it exist in PartLot table or not)
            string Qry = $"LotNumValidation?Company={obj.Company}&PartNum={obj.PartNum}&LotNum={obj.LotNum}";
            HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync(Qry).Result;
            bool isLotExist = response.Content.ReadAsAsync <bool>().Result;

            //AMIN - Check Lot Attribute M or T or else
            LotAttributeModel tempLotAtt = obj.LotAttribute;
            bool isNullAtt = false;

            if ((tempLotAtt.AttBatch == null && tempLotAtt.AttMfgBatch == null && tempLotAtt.AttMfgLot == null && tempLotAtt.AttHeat == null && tempLotAtt.AttFirmware == null && tempLotAtt.AttBeforeDt == null && tempLotAtt.AttMfgDt == null && tempLotAtt.AttCureDt == null && tempLotAtt.AttExpDt == null) ||
                (tempLotAtt.AttBatch == "N" && tempLotAtt.AttMfgBatch == "N" && tempLotAtt.AttMfgLot == "N" && tempLotAtt.AttHeat == "N" && tempLotAtt.AttFirmware == "N" && tempLotAtt.AttBeforeDt == "N" && tempLotAtt.AttMfgDt == "N" && tempLotAtt.AttCureDt == "N" && tempLotAtt.AttExpDt == "N"))
            {
                isNullAtt = true;
            }
            else
            {
                isNullAtt = false;
            }

            //test data
            //objPODtl.TrackLot = true;
            //isLotExist = false;
            //isNullAtt = false;

            //tempLotAtt.AttBeforeDt = "M";
            //tempLotAtt.AttMfgDt = "M";
            //tempLotAtt.AttCureDt = "M";
            //tempLotAtt.AttExpDt = "M";


            //if (objPODtl!=null && objPODtl.TrackLot && !isLotExist)
            if (objPODtl != null && objPODtl.TrackLot && !isLotExist && !isNullAtt)
            {
                //LotNum Validation fails then open LotAttribute Page
                LotAttributeModel objLotAttribute = obj.LotAttribute == null ? objPODtl.LotAttribute : obj.LotAttribute;
                objLotAttribute.LotNum       = obj.LotNum;
                objLotAttribute.DONum        = obj.DONum;
                objLotAttribute.LotShelfLife = obj.LotShelfLife;
                return(View(objLotAttribute));
            }
            else
            {
                //LotNum Validation sucess then open PrintTag Page
                PrintTagModel objPrintTag = new PrintTagModel();
                //if Carton label tick true then prompt the printtag page
                if (!entity.CartonLabel)
                {
                    return(RedirectToAction("ManualUpdate", objPrintTag));
                }
                objPrintTag.Id      = obj.Id;
                objPrintTag.Company = obj.Company;
                objPrintTag.PONum   = obj.PONum;
                objPrintTag.POLine  = obj.POLine;
                objPrintTag.DONum   = obj.DONum;
                objPrintTag.PartNum = obj.PartNum;
                objPrintTag.LotNum  = obj.LotNum;

                ViewBag.Uom     = entity.PODetails.Select(s => s.UomCode).FirstOrDefault <string>();
                ViewBag.UserQty = entity.PODetails.Select(s => s.Qty).FirstOrDefault <decimal>();

                return(RedirectToAction("PrintTag", objPrintTag));
                //return View("PrintTag", objPrintTag);
            }
        }
Exemplo n.º 21
0
        public int Insert(POHeaderModel model)
        {
            string sql =
                @"INSERT INTO po_headers_all
                       (po_num
                       ,po_date
                       ,type_lookup_code
                       ,last_update_date
                       ,last_updated_by
                       ,creation_date
                       ,created_by
                       ,vendor_id
                       ,vendor_site_id
                       ,vendor_num
                       ,ship_to_location_id
                       ,bill_to_location_id
                       ,term_id
                       ,term_code
                       ,currency_code
                       ,rate_type
                       ,rate_date
                       ,rate
                       ,authorization_status
                       ,revision_num
                       ,revised_date
                       ,approved_flag
                       ,approved_date
                       ,remarks
                       ,closed_date
                       ,approval_required_flag
                       ,cancel_flag
                       ,status_code
                       ,tax_code
                       ,tax_rate
                       ,sub_total
                       ,tax_amount
                       ,discount
                       ,freight
                       ,total_amount
                       ,status
                       ,received_flag
                       ,buyer_id
                       ,submit_flag
                       ,job_flag
                       ,revision_notes
                       ,approver_id)
                 VALUES
                       (@po_num
                       ,@po_date
                       ,@type_lookup_code
                       ,@last_update_date
                       ,@last_updated_by
                       ,@creation_date
                       ,@created_by
                       ,@vendor_id
                       ,@vendor_site_id
                       ,@vendor_num
                       ,@ship_to_location_id
                       ,@bill_to_location_id
                       ,@term_id
                       ,@term_code
                       ,@currency_code
                       ,@rate_type
                       ,@rate_date
                       ,@rate
                       ,@authorization_status
                       ,@revision_num
                       ,@revised_date
                       ,@approved_flag
                       ,@approved_date
                       ,@remarks
                       ,@closed_date
                       ,@approval_required_flag
                       ,@cancel_flag
                       ,@status_code
                       ,@tax_code
                       ,@tax_rate
                       ,@sub_total
                       ,@tax_amount
                       ,@discount
                       ,@freight
                       ,@total_amount
                       ,@status
                       ,@received_flag
                       ,@buyer_id
                       ,@submit_flag
                       ,@job_flag
                       ,@revision_notes
                       ,@approver_id)";

            return(db.Insert(sql, Take(model)));
        }
        // POST api/<controller>
        public async Task <string> Post(POViewModel value)
        {
            const long PurchaserHead = 6;
            var        nhss          = new NHibernateISupplierStore();
            var        nhcs          = new NHibernateCompanyStore();
            var        nhpos         = new NHibernatePOStore();
            var        nhus          = new NHibernateUserStore();
            var        company       = new NHibernateCompanyStore();
            var        requierDate   = value.RequiredDate < DateTime.UtcNow ? DateTime.UtcNow.AddDays(6) : value.RequiredDate;
            var        user          = await nhus.FindByStampAsync(value.SecurityStamp);

            var requestor = await nhcs.GetEmployeeAsync(value.RequestorId);

            var po = await nhpos.FindPOAByIdAsync(value.Id);

            if (po == null)
            {
                po = new POHeaderModel()
                {
                    Supplier       = await nhss.FindSupplierByIdAsync(value.SupplierId),
                    PaymentTerm    = value.PaymentTerm,
                    Requestor      = requestor,
                    DeliveryAdress = value.DeliveryAdress,
                    Status         = value.Status,
                    RequiredDate   = requierDate,
                    NoteToBuyer    = value.NoteToBuyer,
                    CreatedBy      = user,
                    Amount         = value.Amount,
                    CRC            = requestor.Team.CRC,
                    Lines          = new List <POLinesModel>()
                };
                foreach (var line in value.Lines)
                {
                    var nhps   = new NHibernatePRStore();
                    var poLine = new POLinesModel()
                    {
                        Quantity    = line.Quantity,
                        UOM         = line.UOM,
                        Description = line.Description,
                        UnitPrice   = line.UnitPrice,
                        PRLine      = await nhps.GetPRLineAsync(line.PRLineId),
                        Name        = line.Name,
                        CreatedBy   = user
                    };
                    po.Lines.Add(poLine);
                }
            }
            else
            {
                po.Requestor = await nhcs.GetEmployeeAsync(value.RequestorId);

                po.DeliveryAdress = value.DeliveryAdress;
                po.Amount         = value.Amount;
                for (var i = 0; i < po.Lines.Count; i++)
                {
                    var found = false;
                    var id    = po.Lines.ElementAt(i).Id;
                    foreach (var line in value.Lines)
                    {
                        if (line.Id == id)
                        {
                            found = true;
                            po.Lines.ElementAt(i).Quantity    = line.Quantity;
                            po.Lines.ElementAt(i).UOM         = line.UOM;
                            po.Lines.ElementAt(i).Description = line.Description;
                            po.Lines.ElementAt(i).UnitPrice   = line.UnitPrice;
                            break;
                        }
                    }
                    if (found == false)
                    {
                        po.Lines.ElementAt(i).DeleteTime = DateTime.UtcNow;
                    }
                }
            }
            if (value.Status == StatusType.ForApproval)
            {
                var approver = new POAprovalModel()
                {
                    Approver = await company.GetPositionByIdAsync(PurchaserHead),
                    Status   = StatusType.ForApproval
                };
                po.Approvals = new List <POAprovalModel>();
                po.Approvals.Add(approver);
                var costApprover = company.FindCostApprover(po.Amount);
                if (costApprover.Result != null)
                {
                    var approver2 = new POAprovalModel()
                    {
                        Approver = costApprover.Result.Approver,
                        Status   = StatusType.ForApproval
                    };
                    po.Approvals.Add(approver2);
                }
            }

            try {
                await nhpos.SaveOrUpdatePOHeaderAsync(po);
            } catch (Exception e) {
            }
            return(po.RequisitionNo);
        }
Exemplo n.º 23
0
        public HttpResponseMessage Post([FromBody] POHeaderModel objPOHeaderModel)
        {
            try
            {
                if (objPOHeaderModel != null)
                {
                    if (objPOHeaderModel.PODetails == null)
                    {
                        throw new Exception("PODetails is Null!");
                    }
                    if (objPOHeaderModel.PODetails.Count() > 1)
                    {
                        throw new Exception("PODetails more than one row!");
                    }

                    var podtlRcvQty = objPOHeaderModel.PODetails.Where(x => x.OrdQty < (x.Qty + x.PrevRcvQty)).SingleOrDefault();
                    if (podtlRcvQty != null)
                    {
                        throw new Exception("Receivng Qty is more than OrderQty!");
                    }
                    var tuid = objPOHeaderModel.PODetails.Select(s => s.TuId).ToList <string>().FirstOrDefault();
                    if (string.IsNullOrEmpty(tuid))
                    {
                        throw new Exception("TuId is Empty!");
                    }
                    var lotNum   = objPOHeaderModel.PODetails.Select(s => s.LotNum).ToList <string>().FirstOrDefault();
                    var tracklot = objPOHeaderModel.PODetails.Select(s => s.TrackLot).ToList <bool>().FirstOrDefault();

                    if (string.IsNullOrEmpty(lotNum) && tracklot)
                    {
                        throw new Exception("LotNum is Empty!");
                    }


                    if (tracklot)
                    {
                        var objLotAtt = objPOHeaderModel.PODetails.Select(s => s.LotAttribute).ToList <LotAttributeModel>().FirstOrDefault();
                        if (objLotAtt == null)
                        {
                            throw new Exception("Lot Attribute is Null!");
                        }
                        else
                        {
                            if (objLotAtt.AttBatch == "M" && string.IsNullOrEmpty(objLotAtt.Batch))
                            {
                                throw new Exception("Batch Attribute is Mandatory!");
                            }

                            if (objLotAtt.AttMfgBatch == "M" && string.IsNullOrEmpty(objLotAtt.MBatch))
                            {
                                throw new Exception("MBatch Attribute is Mandatory!");
                            }
                            if (objLotAtt.AttMfgLot == "M" && string.IsNullOrEmpty(objLotAtt.MLot))
                            {
                                throw new Exception("MLot Attribute is Mandatory!");
                            }

                            if (objLotAtt.AttHeat == "M" && string.IsNullOrEmpty(objLotAtt.Heat))
                            {
                                throw new Exception("Heat Attribute is Mandatory!");
                            }
                            if (objLotAtt.AttFirmware == "M" && string.IsNullOrEmpty(objLotAtt.Firm))
                            {
                                throw new Exception("Firm Attribute is Mandatory!");
                            }

                            if (objLotAtt.AttBeforeDt == "M" && objLotAtt.BestBefore == null)
                            {
                                throw new Exception("BeforeDate Attribute is Mandatory!");
                            }
                            if (objLotAtt.AttMfgDt == "M" && objLotAtt.OrigMfg == null)
                            {
                                throw new Exception("OrigMfg Date Attribute is Mandatory!");
                            }
                            if (objLotAtt.AttCureDt == "M" && objLotAtt.Cure == null)
                            {
                                throw new Exception("CureDate Attribute is Mandatory!");
                            }
                            if (objLotAtt.AttExpDt == "M" && objLotAtt.Expire == null)
                            {
                                throw new Exception("ExpiryDate Attribute is Mandatory!");
                            }
                        }
                    }

                    POHeader      objPOHeader = _pOReceiptModelFactory.Convert(objPOHeaderModel);
                    BusinessLayer BL          = new BusinessLayer();
                    string        msg         = BL.InsertPOHeader(objPOHeader);
                    if (msg == "")
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, msg));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg));
                    }
                }
                else
                {
                    throw new Exception("POHeader is Null!");
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 24
0
        public void UpdatePO(POHeaderModel model)
        {
            model.LastUpdateDate = DateTime.Now;

            factory.POHeaderDao.Update(model);
        }
Exemplo n.º 25
0
 public void DeletePO(POHeaderModel model)
 {
     factory.POHeaderDao.Delete(model);
 }