Button to create Order from Preorder
This commit is contained in:
@@ -437,7 +437,7 @@
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="order_date">Bestelldatum</label>
|
||||
<div class="col-lg-4">
|
||||
<input type="text" class="form-control" name="order_date" id="order_date" value="<?=($order->order_date) ? date("d.m.Y", $order->order_date) : ""?>" />
|
||||
<input type="text" class="form-control" name="order_date" id="order_date" value="<?=(is_numeric($order->order_date)) ? date("d.m.Y", $order->order_date) : $order->order_date ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
@@ -553,7 +553,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body" id="products-form">
|
||||
<h4>Produkte</h4>
|
||||
@@ -585,6 +584,12 @@
|
||||
<div class="row product-container" id="position-<?=$i?>">
|
||||
<input type="hidden" name="products[<?=$i?>][delete]" id="products-<?=$i?>-delete" value="0" />
|
||||
<input type="hidden" name="products[<?=$i?>][orderproduct_id]" value="<?=$product->id?>" />
|
||||
<?php if($product->preorder_id): ?>
|
||||
<input type="hidden" name="products[<?=$i?>][preorder_id]" value="<?=$product->preorder_id?>" />
|
||||
<?php endif; ?>
|
||||
<?php if($product->oaid): ?>
|
||||
<input type="hidden" name="products[<?=$i?>][oaid]" value="<?=$product->oaid?>" />
|
||||
<?php endif; ?>
|
||||
<div class="col-md-1 product-<?=$i?>">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@@ -596,9 +601,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<?php if(!$product->preorder_id): ?>
|
||||
<div class="col-md-12 delete-button-container">
|
||||
<a href="#" class="btn btn-xl btn-outline-danger" onclick="toggleDeletePos(<?=$i?>); return false;"><i class="fas fa-fw fa-trash-can fa-xl pointer"></i></a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -290,6 +290,7 @@
|
||||
<td onclick="toggleOrder(<?=$order->id?>)" class="text-monospace"><?=date("d.m.Y", $order->edit)?></td>
|
||||
<td onclick="toggleOrder(<?=$order->id?>)" class="text-monospace"><?=$order->editor->name?></td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<!--a href="<?=self::getUrl("Order", "createSnoppOrder", ["id" => $order->id, "filter" => $filter, "noTermProducts" => 1])?>" class="mr-2"><img src="<?=self::getResourcePath()?>img/snop-logo.png" /></a-->
|
||||
<?php if($order->waiting == 1): ?>
|
||||
<a href="<?=self::getUrl("Order", "setwaiting", ["id" => $order->id, "unset" => "1", "filter" => $filter, "s" => $pagination['start']])?>"><i class="fas fa-eye-slash" title="Einblenden"></i></a>
|
||||
<?php else: ?>
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
<div class="card-body">
|
||||
<div class="card-header bg-info text-white pl-2 pr-2 pt-1 pb-1">Details</div>
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
<div class="loader-big hidden" ><img src="<?=self::getResourcePath()?>assets/images/loader-big.gif" /></div>
|
||||
@@ -170,6 +172,18 @@
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<div class="row mb-2">
|
||||
<div class="col-8">
|
||||
<?php if($preorder->orderproduct): ?>
|
||||
<a href="<?=self::getUrl("Order", "index", ["id" => $preorder->orderproduct->order_id])?>" target="_blank"><i class="far fa-fw fa-angle-double-right"></i> Internetbestellung anzeigen</a>
|
||||
<?php else: ?>
|
||||
<a href="<?=self::getUrl("Preorder","createOrderFromPreorder", ["preorder_id" => $preorder->id])?>" target="_blank" class="btn btn-outline-primary"><i class="far fa-fw fa-angle-double-right"></i> Internetbestellung anlegen</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-4">
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ class OrderController extends mfBaseController {
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
public function addAction() {
|
||||
//var_dump($this->request->filter);exit;
|
||||
|
||||
|
||||
@@ -969,6 +969,12 @@ class OrderController extends mfBaseController {
|
||||
}
|
||||
|
||||
$product_data = [];
|
||||
if(array_key_exists("preorder_id", $p) && $p["preorder_id"]) {
|
||||
$product_data["preorder_id"] = $p["preorder_id"];
|
||||
}
|
||||
if(array_key_exists("oaid", $p) && $p["oaid"]) {
|
||||
$product_data["oaid"] = $p["oaid"];
|
||||
}
|
||||
$product_data["order_id"] = $new_id;
|
||||
$product_data["product_id"] = $p["product_id"];
|
||||
$product_data['amount'] = (!empty($p['amount'])) ? $p['amount'] : 1;
|
||||
|
||||
@@ -49,10 +49,6 @@ class OrderProduct extends mfBaseModel {
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "cpeprovisioning") {
|
||||
$this->cpeprovisioning = CpeprovisioningModel::getFirst(["orderproduct_id" => $this->id]);
|
||||
return $this->cpeprovisioning;
|
||||
|
||||
@@ -5,6 +5,8 @@ class OrderProductModel
|
||||
public $order_id;
|
||||
public $product_id;
|
||||
public $termination_id;
|
||||
public $oaid;
|
||||
public $preorder_id;
|
||||
public $voicenumber;
|
||||
public $voiceplan_id;
|
||||
public $domain;
|
||||
@@ -212,6 +214,13 @@ class OrderProductModel
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists("preorder_id", $filter)) {
|
||||
$preorder_id = $filter['preorder_id'];
|
||||
if (is_numeric($preorder_id)) {
|
||||
$where .= " AND preorder_id=$preorder_id";
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists("voicenumber", $filter)) {
|
||||
$voicenumber = FronkDB::singleton()->escape($filter['voicenumber']);
|
||||
if ($voicenumber) {
|
||||
|
||||
@@ -26,6 +26,7 @@ class Preorder extends mfBaseModel {
|
||||
private $statusjournals;
|
||||
private $cancel_request_status;
|
||||
private $cancel_request_creator;
|
||||
private $orderproduct;
|
||||
|
||||
protected function beforeUpdate($data) {
|
||||
if(!array_key_exists("edit_by", $data)) {
|
||||
@@ -1690,6 +1691,13 @@ class Preorder extends mfBaseModel {
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
if($name == "orderproduct") {
|
||||
$op = OrderProductModel::getFirst(["preorder_id" => $this->id]);
|
||||
if(!$op) return null;
|
||||
$this->orderproduct = $op;
|
||||
return $this->orderproduct;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-" . $this->create_by);
|
||||
if($user) {
|
||||
|
||||
@@ -1048,6 +1048,157 @@ class PreorderController extends mfBaseController {
|
||||
$this->layout()->set("no_filename", false);
|
||||
}
|
||||
|
||||
protected function createOrderFromPreorderAction() {
|
||||
$preorder_id = $this->request->preorder_id;
|
||||
|
||||
if(!is_numeric($preorder_id) || $preorder_id < 1) {
|
||||
$this->layout()->setFlash("Vorbestellung nicht gefunden!", "error");
|
||||
$this->redirect("Preorder", "Index");
|
||||
}
|
||||
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) {
|
||||
$this->layout()->setFlash("Vorbestellung nicht gefunden!", "error");
|
||||
$this->redirect("Preorder", "Index");
|
||||
}
|
||||
|
||||
$order_data = [];
|
||||
$order_data["preorder_id"] = $preorder->id;
|
||||
|
||||
$owner_data = [];
|
||||
foreach(["company","uid","firstname","lastname","street","zip","city","phone","email"] as $field) {
|
||||
if(!trim($preorder->$field)) {
|
||||
$owner_data[$field] = "";
|
||||
}
|
||||
$owner_data[$field] = trim($preorder->$field);
|
||||
}
|
||||
|
||||
// search owner in Address and add owner_id ...
|
||||
$owner = false;
|
||||
$owners = AddressModel::search($owner_data);
|
||||
foreach($owners as $o) {
|
||||
if(!$this->me->is("employee")) {
|
||||
// external salespartners must not use addresses with customer_number
|
||||
if($o->customer_number) continue;
|
||||
// otherwise use with address
|
||||
$owner = $o;
|
||||
} else {
|
||||
// every address can be used as fallback
|
||||
$owner = $o;
|
||||
|
||||
// if we are employees, customers with customer_number and fibu_primary_account have precedence
|
||||
// but still use addresses with only customer_number as fallback
|
||||
if($o->customer_number) {
|
||||
$owner = $o;
|
||||
if($o->fibu_primary_account) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($owner && $owner->id) {
|
||||
$order_data["owner_id"] = $owner->id;
|
||||
$order_data["owner"] = $owner;
|
||||
} else {
|
||||
// ... otherwise add owner data to order
|
||||
foreach($owner_data as $field => $value) {
|
||||
if(!$preorder->$field) continue;
|
||||
$order_data["owner_".$field] = $value;
|
||||
}
|
||||
$order_data["new_owner"] = 1;
|
||||
}
|
||||
|
||||
if($preorder->order_date) {
|
||||
$order_data["order_date"] = $preorder->order_date;
|
||||
} else {
|
||||
$order_data["order_date"] = $preorder->create;
|
||||
}
|
||||
|
||||
$operator = false;
|
||||
$campaign = $preorder->campaign;
|
||||
if(is_array($campaign->active_operators) && count($campaign->active_operators)) {
|
||||
$campaign_operator = reset($campaign->active_operators);
|
||||
$operator = $campaign_operator->operator;
|
||||
}
|
||||
|
||||
if(!$operator) {
|
||||
$this->layout()->setFlash("Kampagne hat keinen Netzbetreiber!", "error");
|
||||
$this->redirect("Preorder", "Index", ["filter" => ["preordercampaign_id" => $campaign->id]], "preorder=$preorder_id");
|
||||
}
|
||||
|
||||
// try product with correct network id
|
||||
$product = ProductModel::getFirst(["external_id" => $operator->id, "network_id" => $campaign->network_id]);
|
||||
if(!$product) {
|
||||
// else use any product from operator
|
||||
$product = ProductModel::getFirst(["external_id" => $operator->id, "productgroup_id" => TT_PRODUCTGROUP_ID_INTERNET_ACCESS_RESI, "active" => true]);
|
||||
}
|
||||
if($operator->id == 1) {
|
||||
if(!$product) {
|
||||
$product = ProductModel::getFirst([
|
||||
"external" => 0,
|
||||
"productgroup_id" => TT_PRODUCTGROUP_ID_INTERNET_ACCESS_RESI,
|
||||
"network_id" => $campaign->network_id,
|
||||
"attributename" => "termination_required",
|
||||
"attributevalue" => 0,
|
||||
"active" => true
|
||||
]);
|
||||
}
|
||||
if(!$product) {
|
||||
$product = ProductModel::getFirst([
|
||||
"external" => 0,
|
||||
"productgroup_id" => TT_PRODUCTGROUP_ID_INTERNET_ACCESS_RESI,
|
||||
"name" => "%OAN%",
|
||||
"attributename" => "termination_required",
|
||||
"attributevalue" => 0,
|
||||
"active" => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
//var_dump($product);exit;
|
||||
if(!$product) {
|
||||
$this->layout()->setFlash("Keine Produkte für Netzbetreiber gefunden!", "error");
|
||||
$this->redirect("Preorder", "Index", ["filter" => ["preordercampaign_id" => $campaign->id]], "preorder=$preorder_id");
|
||||
}
|
||||
|
||||
$product_data = [];
|
||||
$product_data["preorder_id"] = $preorder->id;
|
||||
$product_data["oaid"] = $preorder->oaid;
|
||||
$product_data["product_id"] = $product->id;
|
||||
$product_data['amount'] = 1;
|
||||
$product_data["pos"] = 1;
|
||||
$product_data["description"] = "";
|
||||
$product_data["price"] = trim($product->price) ? Layout::commaToDot(trim($product->price)) : 0;
|
||||
$product_data["price_setup"] = trim($product->price_setup) ? Layout::commaToDot(trim($product->price_setup)) : 0;
|
||||
|
||||
$product_data["billing_delay"] = ($product->billing_delay) ? $product->billing_delay : 0;
|
||||
if($product_data["billing_delay"] > 6) {
|
||||
$product_data["billing_delay"] = 6;
|
||||
}
|
||||
$product_data["billing_period"] = $product->billing_period;
|
||||
$product_data["contract_term"] = $product->contract_term;
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
$product_data["price_nne"] = $product->price_nne;
|
||||
$product_data["price_nbe"] = $product->price_nbe;
|
||||
}
|
||||
|
||||
$order_data["products"] = [1 => OrderProductModel::create($product_data)];
|
||||
|
||||
//var_dump($order_data["products"]);exit;
|
||||
$order = new Order();
|
||||
$order->update($order_data);
|
||||
|
||||
//var_dump($owner_data);exit;
|
||||
|
||||
$oc = new OrderController();
|
||||
|
||||
$this->layout()->set("order", $order);
|
||||
return $oc->addAction();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
@@ -105,6 +105,7 @@ class ProductModel {
|
||||
LEFT JOIN ProductAttribute ON (ProductAttribute.product_id = Product.id)
|
||||
LEFT JOIN Producttech ON (Product.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProducttechAttribute ON (ProducttechAttribute.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProductNetwork ON (ProductNetwork.product_id = Product.id)
|
||||
WHERE $where
|
||||
GROUP BY Product.id
|
||||
ORDER BY Productgroup.name,Producttech.name,Product.name LIMIT 1
|
||||
@@ -135,6 +136,7 @@ class ProductModel {
|
||||
LEFT JOIN ProductAttribute ON (ProductAttribute.product_id = Product.id)
|
||||
LEFT JOIN Producttech ON (Product.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProducttechAttribute ON (ProducttechAttribute.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProductNetwork ON (ProductNetwork.product_id = Product.id)
|
||||
WHERE $where
|
||||
GROUP BY Product.id
|
||||
) as p
|
||||
@@ -160,6 +162,7 @@ class ProductModel {
|
||||
LEFT JOIN ProductAttribute ON (ProductAttribute.product_id = Product.id)
|
||||
LEFT JOIN Producttech ON (Product.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProducttechAttribute ON (ProducttechAttribute.producttech_id = Producttech.id)
|
||||
LEFT JOIN ProductNetwork ON (ProductNetwork.product_id = Product.id)
|
||||
WHERE $where
|
||||
GROUP BY Product.id
|
||||
ORDER BY Productgroup.name,Producttech.name,Product.name
|
||||
@@ -169,7 +172,7 @@ class ProductModel {
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
@@ -233,6 +236,15 @@ class ProductModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("network_id", $filter)) {
|
||||
$network_id = $filter['network_id'];
|
||||
if(is_numeric($network_id)) {
|
||||
$where .= " AND ProductNetwork.network_id=$network_id";
|
||||
} elseif(is_array($network_id) && count($network_id)) {
|
||||
$where .= " AND ProductNetwork.network_id IN (". implode(",", $network_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = $db->escape($filter['name']);
|
||||
if($name) {
|
||||
@@ -284,7 +296,7 @@ class ProductModel {
|
||||
|
||||
if(array_key_exists("attributevalue", $filter)) {
|
||||
$attributevalue = $db->escape($filter['attributevalue']);
|
||||
if($attributevalue) {
|
||||
if(strlen($attributevalue)) {
|
||||
$where .= " AND ProductAttribute.value = '$attributevalue'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class OrderProductAddPreorderData extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("OrderProduct");
|
||||
$table->addColumn("oaid", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "termination_id"]);
|
||||
$table->addColumn("preorder_id", "integer", ["null" => true, "default" => null, "after" => "preorder_id"]);
|
||||
$table->addColumn("snopp_order_id", "integer", ["null" => true, "default" => null, "after" => "oaid"]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user