WIP Preorder
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
class Preorder extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','email','note'];
|
||||
private $campaign;
|
||||
private $partner;
|
||||
private $building;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -16,11 +18,24 @@ class Preorder extends mfBaseModel {
|
||||
$this->partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->partner_id);
|
||||
if(!$this->partner) {
|
||||
$this->partner = new Address($this->partner_id);
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->partner_id, $this->partner);
|
||||
if($this->partner->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->partner_id, $this->partner);
|
||||
}
|
||||
}
|
||||
return $this->partner;
|
||||
}
|
||||
|
||||
if($name == "building") {
|
||||
$this->building = mfValuecache::singleton()->get("mfObjectmodel-Building-".$this->building_id);
|
||||
if(!$this->building) {
|
||||
$this->building = new Building($this->building_id);
|
||||
if($this->building->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-Building-".$this->building_id, $this->building);
|
||||
}
|
||||
}
|
||||
return $this->building;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($user) {
|
||||
|
||||
@@ -59,6 +59,146 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
$this->layout()->set("products", $products);
|
||||
|
||||
$partners = AddressModel::search(['addresstype' => ['salespartner']]);
|
||||
$this->layout()->set("partners", $partners);
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
var_dump($r);
|
||||
|
||||
/*
|
||||
* add or edit
|
||||
*/
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$preorder = new Preorder($id);
|
||||
if(!$preorder->id) {
|
||||
$this->layout()->setFlash("Vorbestellung nicht gefunden", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
/*
|
||||
* data colletion
|
||||
*/
|
||||
$data = [];
|
||||
$data['preordercampaign_id'] = $r->campaign_id;
|
||||
$data['building_id'] = $r->building_id;
|
||||
$data['termination_id'] = ($r->termination_id) ? $r->termination_id : null;
|
||||
$data['product_id'] = $r->product_id;
|
||||
|
||||
switch($r->type) {
|
||||
case "interest":
|
||||
$data['type'] = "interest";
|
||||
break;
|
||||
case "provision":
|
||||
$data['type'] = "provision";
|
||||
break;
|
||||
case "order":
|
||||
$data['type'] = "order";
|
||||
break;
|
||||
}
|
||||
|
||||
$data['price'] = $r->price;
|
||||
$data['price_setup'] = $r->price_setup;
|
||||
$data['price_nne'] = $r->price_nne;
|
||||
$data['price_nbe'] = $r->price_nbe;
|
||||
$data['billing_delay'] = $r->billing_delay;
|
||||
$data['partner_id'] = $r->partner_id;
|
||||
|
||||
$data['company'] = $r->company;
|
||||
$data['uid'] = $r->uid;
|
||||
$data['firstname'] = $r->firstname;
|
||||
$data['lastname'] = $r->lastname;
|
||||
$data['street'] = $r->street;
|
||||
$data['zip'] = $r->zip;
|
||||
$data['city'] = $r->city;
|
||||
$data['phone'] = $r->phone;
|
||||
$data['email'] = $r->email;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = $this->me->id;
|
||||
$preorder = PreorderModel::create($data);
|
||||
} else {
|
||||
$preorder->update($data);
|
||||
}
|
||||
|
||||
/*
|
||||
* validation
|
||||
*/
|
||||
|
||||
$campaign = new Preordercampaign($preorder->preordercampaign_id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Keine Kampagne ausgewählt!", "error");
|
||||
$this->redirect("Preordercampaign");
|
||||
}
|
||||
|
||||
$product = new Product($data['product_id']);
|
||||
if(!$product->id) {
|
||||
$this->layout()->setFlash("Bitte Produkt auswählen!", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
$preorder->billing_period = $product->billing_period;
|
||||
if(!$this->me->isAdmin()) {
|
||||
$preorder->price_nne = $product->price_nne;
|
||||
$preorder->price_nbe = $product->price_nbe;
|
||||
}
|
||||
|
||||
|
||||
if(!strlen($preorder->price)
|
||||
|| !strlen($preorder->price_setup)
|
||||
|| !strlen($preorder->price_nne)
|
||||
|| !strlen($preorder->price_nbe)
|
||||
|| !strlen($preorder->price_nne)) {
|
||||
$this->layout()->setFlash("Bitte alle benötigten Produktdaten ausfüllen!", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
if(!strlen($preorder->firstname)
|
||||
|| !strlen($preorder->lastname)
|
||||
|| !strlen($preorder->street)
|
||||
|| !strlen($preorder->zip)
|
||||
|| !strlen($preorder->city)) {
|
||||
$this->layout()->setFlash("Bitte alle benötigten Kundendaten ausfüllen!", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var_dump($preorder);exit;
|
||||
|
||||
|
||||
/*
|
||||
* save
|
||||
*/
|
||||
$new_id = $preorder->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->layout()->set("preorder", $preorder);
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
|
||||
$qs = ['filter' => ['campaign_id' => $preorder->preordercampaign_id]];
|
||||
$qs = http_build_query($qs);
|
||||
|
||||
$this->layout()->setFlash("Vorbestellung erfolgreich gespeichert!", "success");
|
||||
$this->redirect("Preorder", "Index", $qs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
<?php
|
||||
|
||||
class PreorderModel {
|
||||
public $name = null;
|
||||
public $network_id = null;
|
||||
public $gps_lat = null;
|
||||
public $gps_long = null;
|
||||
public $location = null;
|
||||
public $vlan_public = null;
|
||||
public $vlan_nat = null;
|
||||
public $vlan_ipv6 = null;
|
||||
public $preordercampaign_id;
|
||||
public $building_id;
|
||||
public $termination_id;
|
||||
public $product_id;
|
||||
public $type;
|
||||
public $price;
|
||||
public $price_setup;
|
||||
public $price_nne;
|
||||
public $price_nbe;
|
||||
public $billing_delay;
|
||||
public $billing_period;
|
||||
public $partner_id;
|
||||
public $company;
|
||||
public $uid;
|
||||
public $firstname;
|
||||
public $lastname;
|
||||
public $street;
|
||||
public $zip;
|
||||
public $city;
|
||||
public $phone;
|
||||
public $email;
|
||||
|
||||
public $note = null;
|
||||
public $note;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
public $create;
|
||||
public $edit;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Preorder();
|
||||
|
||||
Reference in New Issue
Block a user