Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix document, template installer, and calc script #24

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions public/vendor/exment/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ var Exment;
linkElem.closest('a').click();
});
};
/**
* add comma and remove comma if focus
*/
CommonEvent.numberComma = function () {
};
/**
* Set changedata event
*/
Expand All @@ -76,7 +71,7 @@ var Exment;
// get element value from model
var from = modeldata['value'][changedata_from];
// copy to element from model
var val = $elem.prop('number_format') ? comma(from) : from;
var val = $elem.attr('number_format') ? comma(from) : from;
$elem.val(val);
}
CommonEvent.setFormFilter($target);
Expand All @@ -101,7 +96,7 @@ var Exment;
if ($e.data('getitem')) {
continue;
}
var val = $e.prop('number_format') ? comma(data[key]) : data[key];
var val = $e.attr('number_format') ? comma(data[key]) : data[key];
$e.val(val);
// if target-item is "iconpicker-input", set icon
if ($e.hasClass('iconpicker-input')) {
Expand Down Expand Up @@ -218,6 +213,7 @@ var Exment;
if (prefix === void 0) { prefix = ''; }
return '.' + prefix + key + ',.' + prefix + 'value_' + key;
};
CommonEvent.calcDataList = [];
/**
* 日付の計算
*/
Expand Down Expand Up @@ -474,13 +470,18 @@ var Exment;
* Set calc event
*/
CommonEvent.setCalcEvent = function (datalist) {
// set datalist for after flow.
CommonEvent.calcDataList = [];
// loop "data-calc" targets
for (var key in datalist) {
var data = datalist[key];
// set data to element
$(CommonEvent.getClassKey(key)).data('calc_data', data);
// cannot use because cannot fire new row
//$(CommonEvent.getClassKey(key)).data('calc_data', data);
// set calcDataList array. key is getClassKey. data is data
CommonEvent.calcDataList.push({ "classKey": CommonEvent.getClassKey(key), "data": data });
// set calc event
$(document).on('change', CommonEvent.getClassKey(key), { data: data }, function (ev) {
$(document).on('change', CommonEvent.getClassKey(key), { data: data, key: key }, function (ev) {
CommonEvent.setCalc($(ev.target), ev.data.data);
});
// set event for plus minus button
Expand Down Expand Up @@ -555,11 +556,17 @@ var Exment;
}
break;
}
$to.val(bn.toPrecision());
var precision = bn.toPrecision();
$to.val($to.attr('number_format') ? comma(precision) : precision);
// if $to has "calc_data" data, execute setcalc function again
var to_data = $to.data('calc_data');
if (hasValue(to_data)) {
CommonEvent.setCalc($to, to_data);
//var to_data = $to.data('calc_data');
for (var key in CommonEvent.calcDataList) {
var calcData = CommonEvent.calcDataList[key];
// filter $to obj
var $filterTo = $to.filter(calcData.classKey);
if (hasValue($filterTo)) {
CommonEvent.setCalc($filterTo, calcData.data);
}
}
}
};
Expand Down
21 changes: 12 additions & 9 deletions src/Controllers/DocumentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public function getDocumentForm(Request $request, $id){
$isMitsumori = $table_name == 'estimate';
$documentItems = [
['y' => 0, 'fixWidth' => true, 'text' => $isMitsumori ? '見積書' : '請求書', 'align' => 'C', 'font_size' => 20, 'border' => 'TLBR'],
['x' => 0, 'y' => 20, 'width' => 95, 'text' => '${value:company-customer:company-name}', 'font_size' => 15, 'border' => 'B'],

// TO:customer
['x' => 0, 'y' => 20, 'width' => 95, 'text' => '${value:deal:company_customer:company_name}', 'font_size' => 15, 'border' => 'B'],
['x' => 95, 'y' => 20, 'text' => '様'],
['x' => 0, 'y' => 35, 'width' => 30, 'text' => '${value:'.$table_name.'-amount}', 'border' => 'B'],
['x' => 30, 'y' => 35, 'text' => '税込'],
['x' => 0, 'y' => 35, 'width' => 30, 'text' => '${sum:'.$table_name.'_detail:sum_tax_price}', 'align' => 'R', 'border' => 'B'],
['x' => 30, 'y' => 35, 'text' => '円(税込)'],

// company info
['x' => 0, 'y' => 35, 'width' => 20, 'image' => '${base_info:company_stamp}', 'align' => 'R'],
Expand All @@ -43,17 +45,17 @@ public function getDocumentForm(Request $request, $id){
['y' => 65, 'fixWidth' => true, 'text' => 'TEL:${base_info:tel01}-${base_info:tel02}-${base_info:tel03}', 'align' => 'R', 'font_size' => 10],

// tables
['y' => 90, 'fixWidth' => true, 'document_item_type' => 'table', 'font_size' => 8, 'target_table' => $table_name.'-detail', 'table_count' => 10, 'target_columns' => [
['y' => 90, 'fixWidth' => true, 'document_item_type' => 'table', 'font_size' => 8, 'target_table' => $table_name.'_detail', 'table_count' => 10, 'target_columns' => [
['column_name' => 'merchandise', 'width' => '*'],
['column_name' => 'unit-price', 'width' => '20', 'align' => 'R'],
['column_name' => 'unit', 'width' => '20', 'align' => 'C'],
['column_name' => 'price', 'width' => '20', 'align' => 'R'],
['column_name' => 'num', 'width' => '20', 'align' => 'C'],
['column_name' => 'quantity', 'width' => '20', 'align' => 'C'],
['column_name' => 'amount', 'width' => '20', 'align' => 'R'],
['column_name' => 'sum_price', 'width' => '20', 'align' => 'R'],
]],

// comment
['y' => 200, 'fixWidth' => true, 'text' => '備考', 'font_size' => 10],
['y' => 205, 'fixWidth' => true, 'height' => 50, 'border' => 'TLBR'],
['y' => 205, 'fixWidth' => true, 'height' => 50, 'border' => 'TLBR', 'text' => '${value:tekiyou}'],
];
if($isMitsumori){
$documentItems[] = ['x' => 0, 'y' => 45, 'text' => '有効期限:'.Carbon::today()->addMonth()->addDay(-1)->format('Y/m/d')];
Expand All @@ -67,11 +69,12 @@ public function getDocumentForm(Request $request, $id){
$document_attachment_file = $service->getPdfPath();
// save pdf
$path = $this->savePdfInServer($document_attachment_file, $service);
$filename = $service->getPdfFileName();

return response()->file($path, [
'Content-Type' => 'application/pdf',
//'Content-Disposition' => 'inline; filename="'.$filename.'"'
'Content-Disposition' => 'inline;'
'Content-Disposition' => 'inline; filename="'.$filename.'"'
]);


Expand Down
35 changes: 30 additions & 5 deletions src/Services/DocumentPdfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,39 @@ public function makeContractPdf($model, $documentInfo, $documentItems = [])
// get value from model
if (count($length_array) <= 1) {
$str = '';
}else if(count($length_array) == 2) {
$str = getValue($model, $length_array[1], true);
}else{
$str = getValue($model, $length_array[1], $length_array[2]);
}
// elseif(count($length_array) == 2) {
// $str = getValue($model, $length_array[1], true);
// }
//else, getting value recursively
else{
// get comma string from index 1.
$length_array = array_slice($length_array, 1);
$str = getValue($model, implode(',', $length_array), true);
}
$text = str_replace($matches[0][$i], $str, $text);
}
///// sum
elseif (strpos($match, "sum") !== false) {
// get sum value from children model
if (count($length_array) <= 2) {
$str = '';
}
//else, getting value using cihldren
else{
// get children values
$children = getChildrenValues($model, $length_array[1]);
// looping
$sum = 0;
foreach($children as $child){
$sum += intval($child->getValue($length_array[2]));
}
$str = strval($sum);
}
$text = str_replace($matches[0][$i], $str, $text);
}
else if(strpos($match, "base_info") !== false){
// base_info
elseif(strpos($match, "base_info") !== false){
$base_info = getModelName(Define::SYSTEM_TABLE_NAME_BASEINFO)::first();
// get value from model
if (count($length_array) <= 1) {
Expand Down
79 changes: 68 additions & 11 deletions src/Services/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,11 @@ function getRelationName($obj)
*/
function getRelationNamebyObjs($parent, $child)
{
$parent_suuid = CustomTable::getEloquent($parent)->suuid;
$child_suuid = CustomTable::getEloquent($child)->suuid;
$parent_suuid = CustomTable::getEloquent($parent)->suuid ?? null;
$child_suuid = CustomTable::getEloquent($child)->suuid ?? null;
if(is_null($parent_suuid) || is_null($child_suuid)){
return null;
}
return "pivot_{$parent_suuid}_{$child_suuid}";
}
}
Expand Down Expand Up @@ -566,32 +569,83 @@ function getValue($custom_value, $column = null, $isonly_label = false)
if (!function_exists('getValueUseTable')) {
/**
* Get Custom Value
* @param $value
* @param string|array|CustomColumn $column
* @param array|CustomValue $value trget value
* @param string|array|CustomColumn $column target column_name or CustomColumn object. If null, it's label column
* @param mixin $label if column_type is select_table or select_valtext, only get label
* @return string
*/
function getValueUseTable($custom_table, $value, $column = null, $label = false)
{
if (is_null($value)) {
return $nullvalue;
return null;
}

$custom_table = CustomTable::getEloquent($custom_table);
if(is_null($column)){
$column = getLabelColumn($custom_table);
}

// get custom column as array

// if $column is string and and contains comma
if (is_string($column) && str_contains($column, ',')) {
///// getting value Recursively
// split comma
$columns = explode(",", $column);
// if $columns count >= 2, loop columns
if (count($columns) >= 2) {
$loop_value = $value;
$loop_custom_table = $custom_table;
foreach ($columns as $k => $c) {
$lastIndex = ($k != count($columns) - 1);
// if $k is not last index, $loop_label is false(because using CustomValue Object)
if (!$lastIndex) {
$loop_label = false;
}
// if last index, $loop_label is called $label
else {
$loop_label = $label;
}
// get value using $c
$loop_value = getValueUseTable($loop_custom_table, $loop_value, $c, $loop_label);
// if null, return
if (is_null($loop_value)) {
return null;
}

// if last index, return value
if($lastIndex){
return $loop_value;
}
// get custom table. if CustomValue
if($loop_value instanceof CustomValue){
$loop_custom_table = $loop_value->getCustomTable();
}
// else, something wrong, so return null
else{
return null;
}
}
return $loop_value;
}
// if length <= 1, set normal getValueUseTable flow, so $column = $columns[0]
else{
$column = $columns[0];
}
}

///// get custom column as array
// if string
if (is_string($column)) {
$column_first = CustomColumn
::where('column_name', $column)
->where('custom_table_id', $custom_table->id)
->where('custom_table_id', array_get($custom_table, 'id'))
->first();
if(is_null($column_first)){return null;}
$column_array = $column_first->toArray() ?? null;
} elseif ($column instanceof CustomValue) {
}
// if $column is CustomColumn, convert to array.
elseif ($column instanceof CustomColumn) {
$column_array = $column->toArray();
} else {
}
else {
$column_array = $column;
}

Expand All @@ -600,6 +654,9 @@ function getValueUseTable($custom_table, $value, $column = null, $label = false)
if(is_array($value)){
$key = array_get($column_array, 'column_name');
$val = array_get($value, $key);
}elseif($value instanceof CustomValue){
$key = array_get($column_array, 'column_name');
$val = array_get($value->value, $key);
}else{
$val = $value;
}
Expand Down
Loading