예제 #1
0
 public JsonResult SaveProforma(int req, int patientId, string productIds)
 {
     try
     {
         var usr         = (Pharmacies)Session["user"];
         var product_ids = productIds.Split(',').ToList();
         var details     = new List <ProformaDetails>();
         var request     = client.GetRequestById(req);
         foreach (var s in _proforma)
         {
             details.Add(new ProformaDetails
             {
                 Product    = s.Product,
                 Unit       = s.Unit,
                 UnitPrice  = s.UnitPrice,
                 Quantity   = s.Quantity,
                 ProductId  = s.ProductId,
                 Equivalent = s.Equivalent
             });
         }
         Instant now    = SystemClock.Instance.GetCurrentInstant();
         var     utcNow = now.InZone(DateTimeZoneProviders.Tzdb[usr.TimeZone]).ToDateTimeUtc();
         var     profo  = new Proforma
         {
             Amount       = details.Sum(x => (x.UnitPrice * x.Quantity)),
             Currency     = usr.Currency, // la proforma est faite sen la devise de la pharmacie.
             PatientId    = patientId,
             PharmacyId   = usr.Id,
             OrdonnanceId = request.OrdonnanceId,
             DateCreated  = utcNow,
             Status       = 0
         };
         client.CreateProforma(profo, details.ToArray());
         _proforma = null;
         return(Json(new { success = true }));
     }
     catch (FaultException ex)
     {
         return(Json(new { success = false, message = ex.Message }));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }));
     }
 }