Переглянути джерело

ndis code tos changed to int based foreign key

master
patrick 5 роки тому
джерело
коміт
87bc5def45
2 змінених файлів з 57 додано та 15 видалено
  1. +34
    -13
      NdisPrice.php
  2. +23
    -2
      ts.php

+ 34
- 13
NdisPrice.php Переглянути файл

@@ -6,12 +6,13 @@ class NdisPrice{
private $html = '';
private $ndis_table;
private $tos =[];
private $current_year = 2020;
public function __construct(int $year=2019) {
global $wpdb;
if ( $year == "2019"){
$now = new \DateTime();
$year = (int)($now->format("Y"));
//$year = (int)($now->format("Y"));
}
@@ -24,7 +25,8 @@ class NdisPrice{
foreach($results as $r){
$this->tos[$r->code] = $r;

$html .= sprintf('<option value="%s" data-level="%d" data-year="%d" data-unit="%s" data-price="%.2f" data-ot="%s">%.2f - %s %s %s</option>',
$html .= sprintf('<option value="%d" data-ndis="%s" data-level="%d" data-year="%d" data-unit="%s" data-price="%.2f" data-ot="%s">%.2f - %s %s %s</option>',
$r->id,
$r->code,
$r->level,
(int) $r->year,
@@ -61,20 +63,20 @@ class NdisPrice{
return $this->html;
}
public function get_tos_str($ndis_code)
public function get_tos_str($tos_id)
{
//return $this->tos[$ndis_code]->name;
//return $this->tos[$tos_id]->name;
foreach ($this->tos as $r){
if ($ndis_code == $r->code)
if ($tos_id == $r->id)
return $r->name;
}
return "";
}
public function get_tos_full_str($ndis_code)
public function get_tos_full_str($tos_id)
{
foreach ($this->tos as $r){
if ($ndis_code == $r->code){
if ($tos_id == $r->id){
return sprintf("%.2f - %s %s %s",
(float) $r->price,
$r->name,
@@ -85,33 +87,52 @@ class NdisPrice{
return "";
}
public function get_tos_price($ndis_code)
public function get_tos_price($tos_id)
{
foreach ($this->tos as $r){
if ($ndis_code == $r->code)
if ($tos_id == $r->id)
return (float) $r->price;
}
return 0;
}
public function get_tos_unit($ndis_code)
public function get_tos_unit($tos_id)
{
foreach ($this->tos as $r){
if ($ndis_code == $r->code)
if ($tos_id == $r->id)
return $r->unit;
}
return "";
}
public function get_tos_ndis_code($tos_id)
{
foreach ($this->tos as $r){
if ($tos_id == $r->id)
return $r->code;
}
return "";
}
public function get_tos_array()
{
foreach ($this->tos as $r){
$r->tos_full_str = sprintf("%.2f - %s %s %s",
$r->tos_full_str = sprintf("%.2f - %d - %s %s %s",
(float) $r->price,
$r->year,
$r->name,
$this->get_level((int) $r->level),
$r->ot);
}
return $this->tos;
}
}
public function get_id_by_tos($ndis_code , int $year=2019)
{
foreach ($this->tos as $r){
if ($ndis_code == $r->code && $year == $r->year)
return $r->id;
}
return 0; //0 = not found
}
}

+ 23
- 2
ts.php Переглянути файл

@@ -669,6 +669,20 @@ class AcareOffice{
}
}
public function dev_change_ndis_price ($args = array(), $assoc_args = array())
{
echo "list ndis prices\n";
$nd = new NdisPrice();
echo "get tos array\n";
$tosarray = $nd->get_tos_array();
$map = array();
foreach($tosarray as $item){
$map[$item->code] = $item->id;
echo "UPDATE wp1m_acare_ts SET tos_id=$item->id WHERE tos='$item->code' and id > 0; \n";
}
//print_r($map);
}
private function send_email_with_job_link($staff, $start, $finish)
{
$message = file_get_contents(plugin_dir_path(__FILE__) . "/html/email_job.html");
@@ -1465,17 +1479,23 @@ ZOT;
{
$response['nojob'] = true;
}
$response['overall_total'] = 0;
foreach ($summary as $key => $val)
{
$unitprice = $price->get_tos_price($key);
$tos_total = $val * $price->get_tos_price($key);
$response['overall_total'] += $tos_total;
$response['summary'][] = array(
'ndis' => $key,
'tos' => $price->get_tos_full_str($key),
'unitprice'=> $unitprice,
'Hours'=> sprintf("%0.2f", $val),
'tos_total'=> sprintf("%0.2f", $tos_total),
);
}
if (count($summary) > 0){
$response['has_summary'] = true;
$response['overall_total'] = sprintf("%0.2f", $response['overall_total'] );
}
@@ -1536,7 +1556,7 @@ ZOT;
->setDate($now)
->setDueDate($due);
$to_save=[];//all invoices to save;
$price = new NdisPrice($now->format("Y"));//current year;
$price = new NdisPrice(2019);//always 2019 until its being changed;
foreach($rows as $r){
$quantity = $this->get_job_hours($r->start, $r->finish);
@@ -1673,6 +1693,7 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
\WP_CLI::add_command( 'email_jobs', array($bb, 'email_jobs'));
\WP_CLI::add_command( 'feedback_url', array($bb, 'feedback_url'));
\WP_CLI::add_command( 'produce_invoice', array($bb, 'produce_invoice'));
\WP_CLI::add_command( 'dev_change_ndis_price', array($bb, 'dev_change_ndis_price'));
}

//$bb->class_loader();

Завантаження…
Відмінити
Зберегти