Added temporary script to create Contracts from Orders
This commit is contained in:
60
scripts/contract/order2contract.php
Normal file
60
scripts/contract/order2contract.php
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
require("../../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
$me = new User(1);
|
||||
|
||||
foreach(OrderModel::search(["finish_date" => true]) as $order) {
|
||||
if(!is_array($order->products) || !count($order->products)) {
|
||||
echo "keine Produkte in Order ".$order->id."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$contracts = [];
|
||||
$primary_matchcode = false;
|
||||
|
||||
// make contracts but don't save them yet
|
||||
foreach($order->products as $op) {
|
||||
$contract = ContractModel::getFirst(["product_id" => $op->product_id, "orderproduct_id" => $op->id]);
|
||||
if($contract) {
|
||||
if($contract->matchcode) {
|
||||
$primary_matchcode = $contract->matchcode;
|
||||
}
|
||||
echo "Contract für Order ".$order->id." Produkt ".$op->product->name." (".$op->product_id.") schon vorhanden (contract_id ".$contract->id.")\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$contract = ContractModel::createFromOrderproduct($op);
|
||||
$contract->create_by = $me->id;
|
||||
$contract->edit_by = $me->id;
|
||||
|
||||
if($contract->matchcode) {
|
||||
$primary_matchcode = $contract->matchcode;
|
||||
}
|
||||
$contracts[] = $contract;
|
||||
}
|
||||
|
||||
if(!$primary_matchcode) {
|
||||
$primary_matchcode = $order->owner->street.", ".$order->owner->zip." ".$order->owner->city;
|
||||
}
|
||||
|
||||
// set matchcode and save
|
||||
foreach($contracts as $contract) {
|
||||
if(!$contract->matchcode) {
|
||||
$contract->matchcode = $primary_matchcode;
|
||||
|
||||
}
|
||||
//var_dump($contract);exit;
|
||||
$contract->save();
|
||||
|
||||
}
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user