I want to save the ID of a new Sale(); in $sale->voucher_series, how can I achieve this?
$sale = new Sale();
$sale->customerid = $request->customerid;
$sale->userid = \Auth::user()->id;
$sale->proof_type = $request->proof_type;
$sale->voucher_series = $request->saleId;
$sale->date_time = $mytime->toDateString();
$sale->total = $request->total;
$sale->status = 'Registered';
$sale->save();
If your voucher_series column is nullable field then it will work.
$sale = new Sale ();
$sale->customerid = $request->customerid;
$sale->userid = \Auth :: user()->id;
$sale->proof_type = $request->proof_type;
$sale->date_time = $mytime->toDateString ();
$sale->total = $request->total;
$sale->status = 'Registered';
$sale->save();
$sale->voucher_series = $sale->id;
Related
I want to save data for all user that have certain group_id in new table.
For example, i want to save new data to all user who have group_id = 1, but based on my code it only save user_id = 2. It should save user_id = 1 too.
$group = Group::find($req->groupID);
foreach($group->creators as $creator)
$attend = new Attendance;
$attend->groupID = $req->groupID;
$attend->meetingID = $data->id;
$attend->userFeedback = NULL;
$attend->userAttendance = 'Not Attend';
$attend->userID = $creator->id;
$attend->save();
You should run your loop properly. Follow the below code
$group = Group::find($req->groupID);
foreach($group->creators as $creator)
{
$attend = new Attendance();
$attend->groupID = $req->groupID;
$attend->meetingID = $data->id;
$attend->userFeedback = NULL;
$attend->userAttendance = 'Not Attend';
$attend->userID = $creator->id;
$attend->save();
}
I am new to the laravel and trying to store the primary key values of patientid to the foreign key of patient_id in address table
$patdet = $request->patdet;
foreach ($patdet as $patdets) {
$pdet = new Patient();
$pdet->fname = $patdets['fname'];
$pdet->mname = $patdets['mname'];
$pdet->lname = $patdets['lname'];
$pdet->age = $patdets['age'];
$pdet->blood_group = $patdets['bloodgroup'];
$pdet->gender = $patdets['gender'];
$ptid = $pdet->save();
}
$addr = $request->address[0];
$address = new Address;
$address->gps_lat = $addr['gps_lat'];
$address->gps_log = $addr['gps_long'];
$address->house_no = $addr['houseno'];
$address->zipcode = $addr['zip_code'];
$address->street = $addr['street'];
$address->chowk = $addr['chowk'];
$address->city = $addr['city'];
$address->patient_id = $patid->id;
$address->save();
I know that $ptid is a local variable and cannot be used in address table, so how can I store it in address table?
Try the following and ask me if it doesn't work
foreach($request->patdet as $key => $patdets)
{
$pdet = new Patient();
$pdet->fname = $patdets['fname'];
$pdet->mname = $patdets['mname'];
$pdet->lname = $patdets['lname'];
$pdet->age = $patdets['age'];
$pdet->blood_group = $patdets['bloodgroup'];
$pdet->gender = $patdets['gender'];
$pdet->save();
$addr = $request->address[$key];
if($pdet->id > 0 && !empty($addr)){
$addrss = new Address;
$addrss->gps_lat = $addr['gps_lat'];
$addrss->gps_log = $addr['gps_long'];
$addrss->house_no = $addr['houseno'];
$addrss->zipcode = $addr['zip_code'];
$addrss->street = $addr['street'];
$addrss->chowk = $addr['chowk'];
$addrss->city = $addr['city'];
$addrss->patient_id = $pdet->id;
$addrss->save();
}
}
Try the following
$patArray = $request->patdet;
$addressArray = $request->address;
$pId = array();
foreach($patArray as $key => $patdets){
$pdet = new Patient();
$pdet->fname = $patdets['fname'];
$pdet->mname = $patdets['mname'];
$pdet->lname = $patdets['lname'];
$pdet->age = $patdets['age'];
$pdet->blood_group = $patdets['bloodgroup'];
$pdet->gender = $patdets['gender'];
$pdet->save();
$pId[$key] = ($pdet->id > 0) ? $pdet->id : 0;
}
foreach($addressArray as $key => $addr){
$addrss = new Address;
$addrss->gps_lat = $addr['gps_lat'];
$addrss->gps_log = $addr['gps_long'];
$addrss->house_no = $addr['houseno'];
$addrss->zipcode = $addr['zip_code'];
$addrss->street = $addr['street'];
$addrss->chowk = $addr['chowk'];
$addrss->city = $addr['city'];
$addrss->patient_id = array_key_exists($key ,$pId) ? $pId[$key] : 0;
$addrss->save();
$i++;
}
This is my controller in store function save for ministries table.
$ministries = new Ministry;
$ministries->country_id = $request->country_name;
$ministries->township_id = $request->township_name;
$ministries->city_id = $request->city_name;
$ministries->division_id = $request->division_name;
$ministries->ministryCode = $request->ministry_code;
$ministries->ministryName = $request->ministry_name;
$ministries->ministryNameMm = $request->ministry_mm_name;
$ministries->address = $request->address;
$ministries->phone = $request->phone;
$ministries->fax = $request->fax;
$ministries->email = $request->email;
$ministries->website = $request->website;
$ministries->save();
$ministries_id = $ministries->id;
this is save for other table(contact_persons)
for ($i=0; $i < count($request->position_id); $i++) {
$contact_persons = new ContactPerson();
$contact_persons->responsibility_id = $request->responsibility_id[$i];
$contact_persons->position_id = $request->position_id[$i];
$contact_persons->country_id = $request->email[$i];
$contact_persons->township_id = $request->email[$i];
$contact_persons->city_id = $request->email[$i];
$contact_persons->division_id = $request->email[$i];
$contact_persons->customer_id = $request->email[$i];
$contact_persons->address = $request->email[$i];
$contact_persons->home_phone = $request->email[$i];
$contact_persons->mobile = $request->email[$i];
$contact_persons->email = $request->email[$i];
$contact_persons->ministries_id = $ministries_id;
$contact_persons->save();
}
please how to solve and thanks.
I am trying to create an order on Magento 1.7.2 using SOAP API V_2 using .NET consol.
I am always getting the same error "Payment not allowerd" using every payment method.
//create an order with Magento API
MagentoService proxy = new MagentoService();
string sessionId = proxy.login("xxx", "xxx");
int idCarrello = proxy.shoppingCartCreate(sessionId, "1");
proxy.UnsafeAuthenticatedConnectionSharing = false;
shoppingCartCustomerEntity clienteMagento = new shoppingCartCustomerEntity();
clienteMagento.firstname = "name";
clienteMagento.lastname = "surname";
clienteMagento.email = "xxx#mmmm.com";
clienteMagento.mode = "guest";
proxy.shoppingCartCustomerSet(sessionId, idCarrello, clienteMagento, "1");
shoppingCartCustomerAddressEntity indirizzoSpedizione = new shoppingCartCustomerAddressEntity();
shoppingCartCustomerAddressEntity indirizzoBill = new shoppingCartCustomerAddressEntity();
indirizzoSpedizione.mode = "shipping";
indirizzoSpedizione.firstname = clienteMagento.firstname;
indirizzoSpedizione.lastname = clienteMagento.lastname;
indirizzoSpedizione.street = "viale europa 32";
indirizzoSpedizione.city = "Foggia";
indirizzoSpedizione.region = "FG";
indirizzoSpedizione.telephone = "111";
indirizzoSpedizione.postcode = "71122";
indirizzoSpedizione.country_id = "IT";
indirizzoSpedizione.is_default_billing = 0;
indirizzoSpedizione.is_default_shipping = 0;
indirizzoBill.mode = "billing";
indirizzoBill.firstname = clienteMagento.firstname;
indirizzoBill.lastname = clienteMagento.lastname;
indirizzoBill.street = "viale europa 32";
indirizzoBill.city = "Foggia";
indirizzoBill.region = "FG";
indirizzoBill.telephone = "111";
indirizzoBill.postcode = "71122";
indirizzoBill.country_id = "IT";
indirizzoBill.is_default_billing = 0;
indirizzoBill.is_default_shipping = 0;
shoppingCartCustomerAddressEntity[] indirizzi = new shoppingCartCustomerAddressEntity[] { indirizzoSpedizione, indirizzoBill };
proxy.shoppingCartCustomerAddresses(sessionId, idCarrello, indirizzi, "1");
proxy.shoppingCartShippingMethod(sessionId, idCarrello, "flatrate_flatrate", "1");
shoppingCartPaymentMethodResponseEntity[] paymentMethods = proxy.shoppingCartPaymentList(sessionId, idCarrello, "1");
Console.WriteLine(paymentMethods); //paymentMethods is always empty!!
shoppingCartPaymentMethodEntity modoPagamento = new shoppingCartPaymentMethodEntity();
modoPagamento.po_number = null;
modoPagamento.method = "checkmo";
modoPagamento.cc_cid = null;
modoPagamento.cc_owner = null;
modoPagamento.cc_number = null;
modoPagamento.cc_type = null;
modoPagamento.cc_exp_year = null;
modoPagamento.cc_exp_month = null;
proxy.shoppingCartPaymentMethod(sessionId, idCarrello, modoPagamento, "1");
Here is the Exception:
//Payment method is not allowed (I tryed checkmo, banktransfer, etc)
//proxy.shoppingCartOrder(sessionId, idCarrello, "1", new string[] { });
Any idea?
Ifaced with the saeme issue. This is the solution - You forgot product, just add product to sale. Also you must do it according to this order (it will not works in other order):
shoppingCartCustomerSet(guest for simplicity);
shoppingCartCustomerAddresses();
shoppingCartProductAdd();
shoppingCartShippingMethod();
shoppingCartPaymentMethod();
Using MVC3 and razor along with NuGet Doddle Report, I have built a nice report that opens a view model in Excel. I would like to allow the user to supply a filter and sort on the view before the report is exported to Excel.
Are there recommended ways to do this or resources I could check out?
Thanks!
EDIT
Controller code that creates report:
public ReportResult CaseReport()
{
var viewModel = new CasesReportViewModel();
var query = (from c in db.Cases
join customer in db.Customers on c.CustomerID equals customer.CustomerID
join category in db.CaseCategories on c.CaseCategoryID equals category.CaseCategoryID
join tech in db.Technicians on c.TechnicianID equals tech.TechnicianID
join engine in db.EngineModels on c.EngineModelID equals engine.EngineModelID
select new CasesReportViewModel()
{
CustomerName = c.Customer.CustomerName,
UserName = c.UserName,
PromoID = tech.PromoID,
EngineModelName = engine.EngineModelName,
CaseNumber = c.CaseNumber,
BMSWorkorder = c.BMSWorkorder,
CaseStatus = c.CaseStatus,
OpenedBy = c.OpenedBy,
OpenedDate = c.OpenedDate,
ClosedBy = c.ClosedBy,
ClosedDate = c.ClosedDate,
CategoryName = category.CategoryName,
CallerFirstName = c.CallerFirstName,
CallerLastName = c.CallerLastName,
AdditionalContact = c.AdditionalContact,
Qualified = c.Qualified,
Description = c.Description,
ESN = c.ESN,
Mileage = c.Mileage,
DateInService = c.DateInService,
ESTR = c.ESTR,
EDS = c.EDS
});
var report = new Report(query.ToReportSource());
//customize fields
report.TextFields.Title = "Case Report";
AppHelpers app = new AppHelpers();
report.TextFields.Header = "Report Date = " + Convert.ToString(app.GetEasternTime());
report.TextFields.Footer = "Copyright 2012";
//data fields
report.RenderHints.BooleanCheckboxes = true;
report.DataFields["CustomerName"].DataFormatString = "{0:c}";
report.DataFields["UserName"].DataFormatString = "{0:c}";
report.DataFields["EngineModelName"].DataFormatString = "{0:c}";
report.DataFields["CaseNumber"].DataFormatString = "{0:c}";
report.DataFields["BMSWorkorder"].DataFormatString = "{0:c}";
report.DataFields["CategoryName"].DataFormatString = "{0:c}";
report.DataFields["CaseStatus"].DataFormatString = "{0:c}";
report.DataFields["OpenedBy"].DataFormatString = "{0:c}";
report.DataFields["OpenedDate"].DataFormatString = "{0:d}";
report.DataFields["ClosedBy"].DataFormatString = "{0:c}";
report.DataFields["ClosedDate"].DataFormatString = "{0:d}";
report.DataFields["CallerFirstName"].DataFormatString = "{0:c}";
report.DataFields["CallerLastName"].DataFormatString = "{0:c}";
report.DataFields["AdditionalContact"].DataFormatString = "{0:c}";
report.DataFields["Qualified"].DataFormatString = "{0:c}";
report.DataFields["Description"].DataFormatString = "{0:c}";
report.DataFields["ESN"].DataFormatString = "{0:c}";
report.DataFields["Mileage"].DataFormatString = "{0:c}";
report.DataFields["DateInService"].DataFormatString = "{0:d}";
report.DataFields["ESTR"].DataFormatString = "{0:c}";
report.DataFields["EDS"].DataFormatString = "{0:c}";
return new ReportResult(report, new ExcelReportWriter(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileName = "CaseReport" };
}