mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'main' into 'mod/autoroute'
terminado añadir usuarios y fechas a pedidos. añadido inaplazable. color en... See merge request jjimenez/safekat!695
This commit is contained in:
@ -464,7 +464,7 @@ class Cliente extends \App\Controllers\BaseResourceController
|
||||
return null;
|
||||
}
|
||||
$modelPlantillaPreciosCliente = model('App\Models\Clientes\ClientePlantillaPreciosModel');
|
||||
$plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("is_deleted", 0)->first();
|
||||
$plantilla = $modelPlantillaPreciosCliente->where("id", $plantilla_id)->where("deleted_at", null)->first();
|
||||
if ($plantilla == false) {
|
||||
return null;
|
||||
} else {
|
||||
|
||||
@ -135,7 +135,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController
|
||||
Field::inst('tipo_impresion'),
|
||||
Field::inst('user_updated_id'),
|
||||
Field::inst('updated_at'),
|
||||
Field::inst('is_deleted'),
|
||||
Field::inst('tiempo_min')
|
||||
->getFormatter('Format::toDecimalChar')->setFormatter('Format::fromDecimalChar')
|
||||
->validator(
|
||||
@ -205,7 +204,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController
|
||||
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
|
||||
foreach ($data['data'] as $pkey => $values) {
|
||||
// Si no se quiere borrar...
|
||||
if ($data['data'][$pkey]['is_deleted'] != 1) {
|
||||
$process_data['tiempo_min'] = $data['data'][$pkey]['tiempo_min'];
|
||||
$process_data['tiempo_max'] = $data['data'][$pkey]['tiempo_max'];
|
||||
$process_data['tipo'] = $data['data'][$pkey]['tipo'];
|
||||
@ -217,7 +215,6 @@ class ClientePrecios extends \App\Controllers\BaseResourceController
|
||||
if (!empty($response)) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -155,7 +155,6 @@ class Clienteplantillaprecioslineas extends \App\Controllers\BaseResourceControl
|
||||
Field::inst( 'tipo_impresion' ),
|
||||
Field::inst( 'user_updated_id' ),
|
||||
Field::inst( 'deleted_at' ),
|
||||
Field::inst( 'is_deleted' ),
|
||||
Field::inst( 'updated_at' ),
|
||||
Field::inst( 'tiempo_min' )
|
||||
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')
|
||||
|
||||
@ -230,6 +230,10 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
$factura->updated_by = $userModel->getFullName($factura->user_updated_id);
|
||||
$factura->created_at_footer = $factura->created_at ? date(' H:i d/m/Y', strtotime($factura->created_at)) : '';
|
||||
$factura->updated_at_footer = $factura->updated_at ? date(' H:i d/m/Y', strtotime($factura->updated_at)) : '';
|
||||
|
||||
$factura->showDeleteButton = model('App\Models\Facturas\FacturaPagoModel')
|
||||
->where('factura_id', $factura->id)->countAllResults() == 0;
|
||||
|
||||
$this->viewData['facturaEntity'] = $factura;
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Facturas.factura') . ' ' . lang('Basic.global.edit3');
|
||||
@ -692,7 +696,9 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
// Se añade la linea de factura
|
||||
$descripcion = $model_presupuesto->generarLineaPedido($presupuesto->id, true, $linea->pedido_id);
|
||||
$cantidad = intval($presupuesto->tirada) - intval($model_factura->getCantidadLineaPedidoFacturada($linea->id));
|
||||
$base = $cantidad * floatval($presupuesto->total_precio_unidad);
|
||||
$base =
|
||||
floatval($presupuesto->total_aceptado_revisado && $presupuesto->total_aceptado_revisado != 0 ?
|
||||
$presupuesto->total_aceptado_revisado : $presupuesto->total_aceptado);
|
||||
$base = round($base, 2);
|
||||
$total_iva = $base * ($presupuesto->iva_reducido == 1 ? 0.04 : 0.21);
|
||||
// se redondea a dos decimales
|
||||
@ -701,10 +707,9 @@ class Facturas extends \App\Controllers\BaseResourceController
|
||||
|
||||
$data = (object) [
|
||||
'factura_id' => $factura_id,
|
||||
'pedido_linea_impresion_id' => $linea->pedido_id,
|
||||
'pedido_linea_impresion_id' => $pedido_linea_id,
|
||||
'descripcion' => $descripcion[0]->concepto,
|
||||
'cantidad' => $cantidad,
|
||||
'precio_unidad' => $presupuesto->total_precio_unidad,
|
||||
'iva' => $presupuesto->iva_reducido == 1 ? 4 : 21,
|
||||
'base' => $base,
|
||||
'total_iva' => $total_iva,
|
||||
|
||||
@ -101,15 +101,6 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
||||
->validator('Validate::notEmpty', array(
|
||||
'message' => lang('Facturas.validation.requerido'))
|
||||
),
|
||||
Field::inst( 'precio_unidad' )
|
||||
->getFormatter( 'Format::toDecimalChar')->setFormatter( 'Format::fromDecimalChar')
|
||||
->validator('Validate::numeric', array(
|
||||
"decimal" => ',',
|
||||
'message' => lang('Facturas.validation.decimal'))
|
||||
)
|
||||
->validator('Validate::notEmpty', array(
|
||||
'message' => lang('Facturas.validation.requerido'))
|
||||
),
|
||||
Field::inst( 'iva' )
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('Facturas.validation.numerico'))
|
||||
@ -128,7 +119,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
||||
$totales = $this->generate_totales(
|
||||
$values['factura_id'],
|
||||
$values['pedido_linea_impresion_id'],
|
||||
$values['precio_unidad'],
|
||||
$values['total'],
|
||||
$values['iva'],
|
||||
$values['cantidad'],
|
||||
$values['old_cantidad']);
|
||||
@ -152,7 +143,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
||||
$totales = $this->generate_totales(
|
||||
$values['factura_id'],
|
||||
$values['pedido_linea_impresion_id'],
|
||||
$values['precio_unidad'],
|
||||
$values['total'],
|
||||
$values['iva'],
|
||||
$values['cantidad'],
|
||||
$values['old_cantidad']);
|
||||
@ -203,7 +194,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
||||
$model->updateTotales($factura_id);
|
||||
}
|
||||
|
||||
private function generate_totales($factura_id, $pedido_linea_id, $precio_unidad, $iva, $cantidad, $old_cantidad)
|
||||
private function generate_totales($factura_id, $pedido_linea_id, $total, $iva, $cantidad, $old_cantidad)
|
||||
{
|
||||
|
||||
// si es una linea que se refiere a pedido
|
||||
@ -214,6 +205,7 @@ class FacturasLineas extends \App\Controllers\BaseResourceController
|
||||
|
||||
// se calcula y se actualiza el subtotal, total_iva y total
|
||||
// redondeando a 4 decimales el precio_unidad y a dos el resto
|
||||
$precio_unidad = round($total / $old_cantidad, 4);
|
||||
$base = round($precio_unidad * $cantidad, 2);
|
||||
$total_iva = round($base * $iva / 100, 2);
|
||||
$total = round($base + $total_iva, 2);
|
||||
|
||||
@ -57,10 +57,7 @@ class FacturasPagos extends \App\Controllers\BaseResourceController
|
||||
->fields(
|
||||
Field::inst( 'id' ),
|
||||
Field::inst( 'forma_pago_id' ),
|
||||
Field::inst( 'notes' )
|
||||
->validator('Validate::notEmpty', array(
|
||||
'message' => lang('Facturas.validation.requerido'))
|
||||
),
|
||||
Field::inst( 'notes' ),
|
||||
Field::inst( 'fecha_pago_at' )
|
||||
->validator( Validate::dateFormat( 'Y-m-d H:i:s' ) )
|
||||
->getFormatter( Format::dateSqlToFormat( 'Y-m-d H:i:s' ) )
|
||||
|
||||
@ -211,6 +211,8 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
|
||||
public function update($id = null){
|
||||
|
||||
$data = [];
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
@ -242,6 +244,14 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
foreach(array_keys($sanitizedData) as $key){
|
||||
if(str_starts_with($key, "fecha_")){
|
||||
$sanitizedData[$key . "_change_user_id"] =
|
||||
auth()->user()->id;
|
||||
$data[$key . "_change_user"] =
|
||||
model('App\Models\Usuarios\UserModel')->getFullName(auth()->user()->id);
|
||||
}
|
||||
}
|
||||
// JJO
|
||||
$sanitizedData['user_updated_id'] = auth()->user()->id;
|
||||
|
||||
@ -268,10 +278,9 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
$id = $pedidoEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
|
||||
|
||||
$data = [
|
||||
'error' => 0,
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
$data['error'] = 0;
|
||||
$data[$csrfTokenName] = $newTokenHash;
|
||||
|
||||
return $this->respond($data);
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
@ -303,7 +312,15 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
|
||||
$this->obtenerDatosFormulario($pedidoEntity);
|
||||
|
||||
|
||||
$pedidoEntity->fecha_entrega_real_change_user = $pedidoEntity->fecha_entrega_real_change_user_id?model('App\Models\Usuarios\UserModel')->
|
||||
getFullName($pedidoEntity->fecha_entrega_real_change_user_id):"";
|
||||
$pedidoEntity->fecha_impresion_change_user = $pedidoEntity->fecha_impresion_change_user_id?model('App\Models\Usuarios\UserModel')->
|
||||
getFullName($pedidoEntity->fecha_impresion_change_user_id):"";
|
||||
$pedidoEntity->fecha_encuadernado_change_user = $pedidoEntity->fecha_encuadernado_change_user_id?model('App\Models\Usuarios\UserModel')->
|
||||
getFullName($pedidoEntity->fecha_encuadernado_change_user_id):"";
|
||||
$pedidoEntity->fecha_entrega_change_externo_user = $pedidoEntity->fecha_entrega_change_externo_user_id?model('App\Models\Usuarios\UserModel')->
|
||||
getFullName($pedidoEntity->fecha_entrega_change_externo_user_id):"";
|
||||
|
||||
$this->viewData['pedidoEntity'] = $pedidoEntity;
|
||||
|
||||
if($pedidoEntity->estado == 'validacion'){
|
||||
@ -321,6 +338,7 @@ class Pedido extends \App\Controllers\BaseResourceController
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
}
|
||||
|
||||
|
||||
@ -366,6 +366,36 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
PresupuestoService::crearPedido($id);
|
||||
}
|
||||
|
||||
// modificar los datos del pedido y de la factura si no está la factura validada
|
||||
if ($presupuestoEntity->estado_id == 2){
|
||||
$facturaModel = model('App\Models\Facturas\FacturaModel');
|
||||
if(!$facturaModel->presupuestoHasFacturaValidada($id)){
|
||||
// se actualiza primero el pedido
|
||||
$pedidoModel = model('App\Models\Pedidos\PedidoLineaModel');
|
||||
$pedidoLineaId = $pedidoModel->where('presupuesto_id', $id)->first()->id;
|
||||
$linea_pedido = $this->model->generarLineaPedido($id)[0];
|
||||
$idPedido = $pedidoModel->join('pedidos', 'pedidos_linea.pedido_id = pedidos.id')
|
||||
->where('pedidos_linea.presupuesto_id', $id)
|
||||
->first()->pedido_id;
|
||||
$pedidoModel->update($pedidoLineaId, [
|
||||
'cantidad' => $linea_pedido->unidades,
|
||||
'descripcion' => $linea_pedido->concepto
|
||||
]);
|
||||
|
||||
// se actualiza la factura
|
||||
$linea_pedido = $this->model->generarLineaPedido($id, true, $idPedido)[0];
|
||||
$facturaLineaModel = model('App\Models\Facturas\FacturaLineaModel');
|
||||
$facturaLineaId = $facturaLineaModel->where('pedido_linea_impresion_id', $pedidoLineaId)->
|
||||
where('deleted_at', null)->first()->id;
|
||||
$facturaLineaModel->update($facturaLineaId, [
|
||||
'cantidad' => $linea_pedido->unidades,
|
||||
'descripcion' => $linea_pedido->concepto
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
|
||||
@ -15,6 +15,7 @@ use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\I18n\Time;
|
||||
use CodeIgniter\Validation\Validation;
|
||||
use Config\LogoImpresion;
|
||||
use Exception;
|
||||
use Hermawan\DataTables\DataTable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
@ -276,16 +277,26 @@ class Ordentrabajo extends BaseController
|
||||
}
|
||||
public function get_portada_img($orden_trabajo_id)
|
||||
{
|
||||
$ot = $this->otModel->find($orden_trabajo_id);
|
||||
if ($ot->portada_path) {
|
||||
$filePath = WRITEPATH . 'uploads/' . $ot->portada_path;
|
||||
$mimeType = mime_content_type($filePath);
|
||||
return $this->response
|
||||
->setHeader('Content-Type', $mimeType)
|
||||
->setHeader('Content-Length', filesize($filePath))
|
||||
->setBody(file_get_contents($filePath));
|
||||
} else {
|
||||
return $this->response->setJSON(["message" => "Portada error", "error" => "No hay portada"])->setStatusCode(400);
|
||||
try {
|
||||
$ot = $this->otModel->find($orden_trabajo_id);
|
||||
if ($ot->portada_path) {
|
||||
$filePath = WRITEPATH . 'uploads/' . $ot->portada_path;
|
||||
if (file_exists($filePath)) {
|
||||
|
||||
$mimeType = mime_content_type($filePath);
|
||||
return $this->response
|
||||
->setHeader('Content-Type', $mimeType)
|
||||
->setHeader('Content-Length', filesize($filePath))
|
||||
->setBody(file_get_contents($filePath));
|
||||
} else {
|
||||
throw new Exception('File' . $ot->portada_path . ' does not exist');
|
||||
}
|
||||
} else {
|
||||
return $this->response->setJSON(["message" => "Portada error", "error" => "No hay portada"])->setStatusCode(400);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
return $this->response->setJSON(["message" => "Portada error", "error" => $th->getMessage()])->setStatusCode(500);
|
||||
|
||||
}
|
||||
}
|
||||
public function planning_rotativa_datatable()
|
||||
@ -302,8 +313,8 @@ class Ordentrabajo extends BaseController
|
||||
{
|
||||
$q = $this->produccionService->planningPlanaQueryDatatable();
|
||||
$padreId = $this->request->getGet('padre_id');
|
||||
if($padreId){
|
||||
$q->where('lg_maquinas.padre_id',$padreId);
|
||||
if ($padreId) {
|
||||
$q->where('lg_maquinas.padre_id', $padreId);
|
||||
}
|
||||
return DataTable::of($q)
|
||||
->edit("tiempo_real_sum", fn($q) => $q->tiempo_real_sum)
|
||||
@ -372,9 +383,9 @@ class Ordentrabajo extends BaseController
|
||||
$ps = $this->produccionService->init($bodyData["orden_trabajo_id"]);
|
||||
$existingFiles = json_decode($bodyData["oldFiles"]);
|
||||
$ps->deleteOtFiles($existingFiles);
|
||||
if($files){
|
||||
if ($files) {
|
||||
$response = $ps->storeOtFiles($files);
|
||||
}else{
|
||||
} else {
|
||||
$response = null;
|
||||
}
|
||||
return $this->response->setJSON([
|
||||
|
||||
Reference in New Issue
Block a user