Not creating SPIN if there is at least one ext product
This commit is contained in:
@@ -792,14 +792,16 @@ class OrderController extends mfBaseController {
|
||||
}
|
||||
|
||||
// add techcontact as AddressLink to owner if not exists
|
||||
$link = AddressLinkModel::getFirst(['address_id' => $techcontact->id, 'origin_address_id' => $order->owner_id, 'type' => "techcontact"]);
|
||||
if(!$link) {
|
||||
$linkdata = [];
|
||||
$linkdata['address_id'] = $techcontact->id;
|
||||
$linkdata['origin_address_id'] = $order->owner_id;
|
||||
$linkdata['type'] = "techcontact";
|
||||
$link = AddressLinkModel::create($linkdata);
|
||||
$link->save();
|
||||
if($techcontact->id) {
|
||||
$link = AddressLinkModel::getFirst(['address_id' => $techcontact->id, 'origin_address_id' => $order->owner_id, 'type' => "techcontact"]);
|
||||
if(!$link) {
|
||||
$linkdata = [];
|
||||
$linkdata['address_id'] = $techcontact->id;
|
||||
$linkdata['origin_address_id'] = $order->owner_id;
|
||||
$linkdata['type'] = "techcontact";
|
||||
$link = AddressLinkModel::create($linkdata);
|
||||
$link->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -905,59 +907,64 @@ class OrderController extends mfBaseController {
|
||||
$owner->save();
|
||||
}
|
||||
}
|
||||
|
||||
// generate and send Service PIN
|
||||
// only if owner_id wasn't changed
|
||||
if(!$owner->spin && (!property_exists($order->_old_data, "owner_id") || $order->owner_id == $order->_old_data->owner_id)) {
|
||||
$this->log->debug(__CLASS__."::save(): creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
$spin = $owner->generateServicePin();
|
||||
if($spin && !AddressModel::search(['spin' => $spin])) {
|
||||
$owner->spin = $spin;
|
||||
if($owner->save()) {
|
||||
|
||||
// render service pin PDF
|
||||
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
|
||||
$pdfpath = $pdf->render();
|
||||
$tvalue = $pdf->getReturnedValues();
|
||||
$pdfname = $tvalue['filename'];
|
||||
|
||||
// send email to customer
|
||||
// TODO template rendern auslagern nach Emailtempate klasse
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/customer/new_order");
|
||||
$tpl->set("owner", $owner);
|
||||
$body = $tpl->render();
|
||||
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
$to = $owner->email;
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-Xinon-Oid", $order->id);
|
||||
$email->setHeader("X-Xinon-Pid", $product->id);
|
||||
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::save(): Sending new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$this->log->debug(__CLASS__."::save(): NOT creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id."): SPIN exists or owner of Order was changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// generate and send Service PIN, only if:
|
||||
// - owner does not have a Service PIN yet
|
||||
// - there are no external products
|
||||
// - owner_id was not set before or owner_id wasn't changed
|
||||
|
||||
// TODO: move this to Order class
|
||||
if(!$ext_products && !$owner->spin && (!property_exists($order->_old_data, "owner_id") || $order->owner_id == $order->_old_data->owner_id)) {
|
||||
$this->log->debug(__CLASS__."::save(): creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
$spin = $owner->generateServicePin();
|
||||
if($spin && !AddressModel::search(['spin' => $spin])) {
|
||||
$owner->spin = $spin;
|
||||
if($owner->save()) {
|
||||
|
||||
// render service pin PDF
|
||||
$pdf = new PdfForm("Emailtemplates/attachments/new_order_spin.pdf", ["owner" => $owner, "order" => $order]);
|
||||
$pdfpath = $pdf->render();
|
||||
$tvalue = $pdf->getReturnedValues();
|
||||
$pdfname = $tvalue['filename'];
|
||||
|
||||
// send email to customer
|
||||
// TODO template rendern auslagern nach Emailtempate klasse
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/customer/new_order");
|
||||
$tpl->set("owner", $owner);
|
||||
$body = $tpl->render();
|
||||
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
$to = $owner->email;
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
|
||||
} else {
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-Xinon-Oid", $order->id);
|
||||
$email->setHeader("X-Xinon-Pid", $product->id);
|
||||
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::save(): Sending new SPIN for ".$owner->getCompanyOrName()." (".$owner->id.")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$this->log->debug(__CLASS__."::save(): NOT creating new SPIN for ".$owner->getCompanyOrName()." (".$owner->id."): SPIN exists or owner of Order was changed or external products");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//var_dump($_FILES['OrderFileUpload']);exit;
|
||||
|
||||
Reference in New Issue
Block a user