Ejemplo n.º 1
0
        public ActionResult purchaseInvoice(int?id)
        {
            if (id != null)
            {
                purchaseList p = new purchaseList();

                var t = db.purchases.Find(id);

                p.create_date = t.create_date;
                p.purchase_id = t.purchase_id;

                //get suplier name
                var s = db.Supplier_tbl.Find(t.supplier_id);
                p.sName           = s.Name;
                p.sPhone          = s.Phone;
                p.sMail           = s.Mail;
                p.sContact_Person = s.Contact_Person;

                p.total_amount = t.total_amount;

                // get all purchase product
                var pd = db.purchase_details.Where(a => a.purchase_id == p.purchase_id).ToList();

                List <purchase_de> pde = new List <purchase_de>();
                foreach (var r in pd)
                {
                    var pi = db.product_tbl.Find(r.product_id);
                    pde.Add(new purchase_de
                    {
                        id             = r.id,
                        purchase_id    = r.purchase_id,
                        purchase_price = r.purchase_price,
                        quantity       = r.quantity,
                        sale_price     = r.sale_price,
                        sku            = r.sku,

                        //get product name;
                        product_name = pi.p_name,
                    });
                }
                p.purchaseDetialsList = pde;
                ViewBag.Message       = TempData["Message"];
                ViewBag.Status        = TempData["Status"];
                return(View(p));
            }
            else
            {
                message = "Try Agine there are some Problems";
                return(RedirectToAction("Create"));
            }
        }
Ejemplo n.º 2
0
        public IActionResult crudPurchase([FromBody] purchaseList obj)
        {
            //***** Try Block
            try
            {
                //****** Declaration
                int           rowAffected = 0;
                string        sqlResponse = "";
                IActionResult response    = Unauthorized();

                using (IDbConnection con = new SqlConnection(db.dbCon))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    DynamicParameters parameters = new DynamicParameters();
                    parameters.Add("@SubLocID", obj.subLocID);
                    parameters.Add("@OfficesecID", obj.officeSecID);
                    parameters.Add("@ProjectID", obj.projectID);
                    parameters.Add("@IPcRef", obj.iPcRef);
                    parameters.Add("@PurchaseDate", obj.purchaseDate);
                    parameters.Add("@TotalAmount", obj.totalAmount);
                    parameters.Add("@Description", obj.description);
                    parameters.Add("@MemoNo", obj.memoNo);
                    parameters.Add("@MemoDate", obj.memoDate);
                    parameters.Add("@MemoIssuedBy", obj.memoIssuedBy);
                    parameters.Add("@MemoEDoc", obj.memoEDoc);
                    parameters.Add("@MemoEDocExtension", obj.memoEDocExtension);
                    parameters.Add("@Supplier", obj.supplier);
                    parameters.Add("@SuppluerInvNo", obj.supplierInvNo);
                    parameters.Add("@SupplierInVDate", obj.supplierInVDate);
                    parameters.Add("@SupplierInvEDoc", obj.supplierInvEDoc);
                    parameters.Add("@SupplierEDocExtension", obj.supplierEDocExtension);
                    parameters.Add("@ModeofAcq", obj.modeofAcq);
                    parameters.Add("@SpType", obj.spType);
                    parameters.Add("@Userid", obj.userid);
                    parameters.Add("@PurchaseID", obj.purchaseID);
                    parameters.Add("@ResponseMessage", dbType: DbType.String, direction: ParameterDirection.Output, size: 5215585);
                    parameters.Add("@PID", dbType: DbType.Int32, direction: ParameterDirection.Output, size: 5215585);

                    rowAffected = con.Execute("dbo.Sp_Purchases", parameters, commandType: CommandType.StoredProcedure);

                    sqlResponse = parameters.Get <string>("@ResponseMessage");

                    int SeqId = 0;
                    if (sqlResponse.ToUpper() == "SUCCESS")
                    {
                        SeqId = parameters.Get <int>("@PID");
                    }

                    //first image
                    if (obj.memoImgFile != null && SeqId != 0)
                    {
                        String path = obj.memoEDoc; //Path

                        //Check if directory exist
                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path); //Create directory if it doesn't exist
                        }

                        string imageName = SeqId + "_memo." + obj.memoEDocExtension;

                        //set the image path
                        string imgPath = Path.Combine(path, imageName);

                        //delete image portion start
                        if (System.IO.File.Exists(Path.Combine(path, imageName)))
                        {
                            System.IO.File.Delete(Path.Combine(path, imageName));
                        }
                        //delete image portion end

                        byte[] imageBytes = Convert.FromBase64String(obj.memoImgFile);

                        System.IO.File.WriteAllBytes(imgPath, imageBytes);
                    }

                    //2nd image
                    if (obj.supplierImgFile != null && sqlResponse.ToUpper() == "SUCCESS")
                    {
                        SeqId = parameters.Get <int>("@PID");

                        String path = obj.supplierInvEDoc; //Path

                        //Check if directory exist
                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path); //Create directory if it doesn't exist
                        }

                        string imageName = SeqId + "_supplier." + obj.supplierEDocExtension;

                        //set the image path
                        string imgPath = Path.Combine(path, imageName);

                        //delete image portion start
                        if (System.IO.File.Exists(Path.Combine(path, imageName)))
                        {
                            System.IO.File.Delete(Path.Combine(path, imageName));
                        }
                        //delete image portion end

                        byte[] imageBytes = Convert.FromBase64String(obj.supplierImgFile);

                        System.IO.File.WriteAllBytes(imgPath, imageBytes);
                    }

                    response = Ok(new { msg = sqlResponse, purID = SeqId });
                }


                return(response);
            }
            //***** Exception Block
            catch (Exception ex)
            {
                return(Ok(new { msg = ex.Message }));
            }
        }