added send customer to IVT
This commit is contained in:
@@ -609,6 +609,15 @@
|
||||
<div class="card-body">
|
||||
|
||||
<?php if($me->is("Admin", "netoperator")): ?>
|
||||
<?php if($order->id): ?>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2"></label>
|
||||
<div class="col-lg-10 mb-2">
|
||||
<button type="button" id="savetoivt-button" class="btn btn-info">Kunde an IVT übertragen</button>
|
||||
<span id="savetoivt-info"></span>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2"></label>
|
||||
<div class="col-lg-10">
|
||||
@@ -662,6 +671,41 @@
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
<?php if($order->id): ?>
|
||||
$('#savetoivt-button').click(function() {
|
||||
$('#savetoivt-button').prop("disabled", true);
|
||||
$('#savetoivt-info').html("<img src='<?=self::getResourcePath()?>img/ajax-loader.gif' />");
|
||||
$.get("<?=self::getUrl("IvtCustomer","create", ["order_id" => $order->id])?>",
|
||||
{},
|
||||
function(data) {
|
||||
console.log(data);
|
||||
if(data.status == "OK") {
|
||||
$('#savetoivt-info').removeClass("text-danger");
|
||||
$('#savetoivt-info').addClass("text-success");
|
||||
$('#savetoivt-info').text("Kunde erfolgreich an IVT übertragen!");
|
||||
$('#savetoivt-button').remove();
|
||||
} else {
|
||||
$('#savetoivt-info').removeClass("text-success");
|
||||
$('#savetoivt-info').addClass("text-danger");
|
||||
if(data.reason) {
|
||||
if(data.reason == "no-cust-num") {
|
||||
$('#savetoivt-info').text("Inhaber und/oder Rechungsempfänger hat keine Kundennummer!");
|
||||
}
|
||||
if(data.reason == "ivt-exist") {
|
||||
$('#savetoivt-info').text("Kunde existiert bereits im IVT!");
|
||||
}
|
||||
} else {
|
||||
$('#savetoivt-info').text("Fehler bei übertragung.");
|
||||
}
|
||||
$('#savetoivt-button').prop("disabled", false);
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
<?php endif; ?>
|
||||
|
||||
$('#owner_id').change(function() {
|
||||
var val = $('#owner_id').val();
|
||||
|
||||
|
||||
86
application/IvtCustomer/IvtCustomer.php
Normal file
86
application/IvtCustomer/IvtCustomer.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
class IvtCustomer extends mfBaseModel {
|
||||
protected $forcestr = ['company','firstname','surname','zip','street','location','housenumber','phone','email','extrainfo'];
|
||||
|
||||
/**
|
||||
* Takes ID or DB row as arguments
|
||||
* @param id or table row $_
|
||||
*/
|
||||
public function __construct($_=NULL) {
|
||||
$this->log = mfLoghandler::singleton();
|
||||
$this->table = get_class($this);
|
||||
$this->data = new stdClass();
|
||||
$this->table = "customers";
|
||||
|
||||
$this->db = new FronkDB(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
if(is_numeric($_)) {
|
||||
$this->fetch($_);
|
||||
} elseif(is_object($_)) {
|
||||
$this->load($_);
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
// get AUTO_INCREMENT value
|
||||
$safe_ai = $this->getAutoIncrementId();
|
||||
if(!$safe_ai) {
|
||||
return false;
|
||||
}
|
||||
$this->log->debug(__CLASS__.": auto increment value: $safe_ai");
|
||||
// save customer
|
||||
|
||||
$fields = [];
|
||||
$fields['id'] = $this->id;
|
||||
foreach($this->data as $name => $value) {
|
||||
$fields[$name] = $value;
|
||||
}
|
||||
|
||||
if(!$this->db->insert($this->table, $fields, $this->forcestr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// reset AUTO_INCREMENT value
|
||||
if($this->setAutoIncrementId($safe_ai)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->log->error(__CLASS__.": Unable to reset AUTO_INCREMENT value");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private function getAutoIncrementId() {
|
||||
$sql = "SELECT `AUTO_INCREMENT` as ai
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = 'ivt_xinon'
|
||||
AND TABLE_NAME = '".$this->table."'";
|
||||
$this->log->debug(__CLASS__.": $sql");
|
||||
$res = $this->db->query($sql);
|
||||
if($this->db->num_rows($res)) {
|
||||
$data = $this->db->fetch_object($res);
|
||||
return $data->ai;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function setAutoIncrementId($ai) {
|
||||
$sql = "ALTER TABLE ".$this->table." AUTO_INCREMENT=$ai";
|
||||
$this->log->debug(__CLASS__.": $sql");
|
||||
|
||||
if($this->db->query($sql)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public function __debugInfo() {
|
||||
$vars = get_object_vars($this);
|
||||
if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
|
||||
if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
|
||||
return $vars;
|
||||
}
|
||||
|
||||
}
|
||||
107
application/IvtCustomer/IvtCustomerController.php
Normal file
107
application/IvtCustomer/IvtCustomerController.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
class IvtCustomerController extends mfBaseController {
|
||||
|
||||
protected function createAction() {
|
||||
$order_id = $this->request->order_id;
|
||||
$order = new Order($order_id);
|
||||
if(!$order->id) {
|
||||
$this->layout()->setFlash("Bestellung nicht gefunden.", "error");
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
$contact = $order->$billingaddress;
|
||||
if(!$contact) {
|
||||
$contact = $order->owner;
|
||||
} else {
|
||||
$contact->customer_number = $order->owner->customer_number;
|
||||
}
|
||||
|
||||
if(!$contact->customer_number) {
|
||||
$return = ['status' => 'error', 'reason' => "no-cust-num"];
|
||||
$this->returnJson($return);
|
||||
}
|
||||
|
||||
$ivtc = new IvtCustomer($contact->customer_number);
|
||||
//var_dump($ivtc);
|
||||
|
||||
if($ivtc->id) {
|
||||
$return = ['status' => 'error', 'reason' => "ivt-exist"];
|
||||
$this->returnJson($return);
|
||||
}
|
||||
|
||||
|
||||
$ivtc->title = "";
|
||||
$ivtc->nick = "";
|
||||
$ivtc->pwd = "";
|
||||
$ivtc->bankcode = "";
|
||||
$ivtc->accountnumber = "";
|
||||
$ivtc->bill_row1 = "";
|
||||
$ivtc->bill_row2 = "";
|
||||
$ivtc->bill_row3 = "";
|
||||
$ivtc->bill_row4 = "";
|
||||
|
||||
$ivtc->id = $contact->customer_number;
|
||||
$ivtc->company = str_replace("\r\n", " ", str_replace("\n", " ", $contact->company));
|
||||
if($contact->company) {
|
||||
$ivtc->firstname = "";
|
||||
$ivtc->surname = str_replace("\r\n", " ", str_replace("\n", " ", $contact->company));
|
||||
}
|
||||
$ivtc->UID = ""; // XXX
|
||||
$ivtc->zip = $contact->zip;
|
||||
$ivtc->location = $contact->city;
|
||||
|
||||
// get housenumber
|
||||
$m = [];
|
||||
if(preg_match('/^(.+)\s+([^ ]+$)/', $contact->street, $m)) {
|
||||
if($m[1]) {
|
||||
$ivtc->street = $m[1];
|
||||
if($m[2]) {
|
||||
$ivtc->housenumber = $m[2];
|
||||
} else {
|
||||
$ivtc->housenumber = "";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ivtc->street = $contact->street;
|
||||
$ivtc->housenumber = "";
|
||||
}
|
||||
|
||||
$ivtc->phone = $contact->phone;
|
||||
$ivtc->email = $contact->email;
|
||||
|
||||
if($order->billing_type == "sepa") {
|
||||
$ivtc->payment = 0; // 0 = sepa / 1 = rechnung
|
||||
$ivtc->BIC = $order->bank_account_bic;
|
||||
$ivtc->IBAN = $order->bank_account_iban;
|
||||
} else {
|
||||
$ivtc->payment = 1; // 0 = sepa / 1 = rechnung
|
||||
$ivtc->BIC = "";
|
||||
$ivtc->IBAN = "";
|
||||
}
|
||||
|
||||
$ivtc->paper_invoice = 0;
|
||||
if(!$contact->email) {
|
||||
$ivtc->paper_invoice = 1;
|
||||
}
|
||||
|
||||
$ivtc->MandatID = ($contract->spin) ? $contract->spin : 1;
|
||||
|
||||
$ivtc->egn = 0; // 0=keine;1=pdf;2=cdr
|
||||
$ivtc->accept_adver = $order->allow_contact;
|
||||
$ivtc->accept_info = $order->allow_spin;
|
||||
$ivtc->telephony_pricelist = 2;
|
||||
$ivtc->extrainfo = $order->note;
|
||||
|
||||
//var_dump($ivtc);
|
||||
|
||||
|
||||
|
||||
if($ivtc->save()) {
|
||||
$return = ['status' => 'OK', 'reason' => ""];
|
||||
} else {
|
||||
$return = ['status' => 'error', 'reason' => "save"];
|
||||
}
|
||||
$this->returnJson($return);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,10 @@ class Order extends mfBaseModel {
|
||||
return $terminations;
|
||||
}
|
||||
|
||||
public function createIvtCustomer($data) {
|
||||
|
||||
}
|
||||
|
||||
public function deletePositions() {
|
||||
if(!is_array($this->getProperty("products")) || !count($this->getProperty("products"))) {
|
||||
return true;
|
||||
|
||||
@@ -166,7 +166,6 @@ class OrderController extends mfBaseController {
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
|
||||
protected function addAction() {
|
||||
// TODO: filter by network permissions
|
||||
$this->layout()->setTemplate("Order/Form");
|
||||
|
||||
BIN
public/img/ajax-loader.gif
Normal file
BIN
public/img/ajax-loader.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Reference in New Issue
Block a user