Skip to content

Commit

Permalink
#324 Temporarily solution for new product modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorr.it committed Jan 5, 2023
1 parent c74bc33 commit a13919c
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 47 deletions.
7 changes: 1 addition & 6 deletions app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
{% endblock %}
</head>
<body>
<div class="modal fade" tabindex="-1" role="dialog" id="modalOrderEditor" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content"></div>
</div>
</div>


<div class="modal fade" tabindex="-1" role="dialog" id="modalConfirm" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand Down
27 changes: 25 additions & 2 deletions src/AppBundle/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ public function indexAction(Request $request)
));
}

/**
* Temporarily solution as long as New Product section is Vue and Order sections are Twig.
* The route is rather complex:
*
* 1. New product selection by user in PurchaseOrder/edit.html.twig (and same for SalesOrder)
* 2. This action ProductController::new (just forwarding props)
* 3. Bare Twig container file Product/new.html.twig (again forwarding props)
* 4. Entrypoint config in webpack.config.js
* 5. ProductNew/app.js
* 6. ProductNew/App.vue (and again forwarding props)
* 7. Reuse of ModalEdit.vue (originally made for product edit)
* 8. Retrieval of product object by AJAX in VueProductController::new
*
* @Route("/new/{purchaseOrderId}/{salesOrderId}/{productTypeId}", name="product_new")
*/
public function newAction(Request $request, $purchaseOrderId = 0, $salesOrderId = 0, $productTypeId = 0)
{
return $this->render('AppBundle:Product:new.html.twig', array(
'purchaseOrderId' => $purchaseOrderId,
'salesOrderId' => $salesOrderId,
'productTypeId' => $productTypeId
));
}

/**
* @Route("/bulkedit/{success}", name="product_bulkedit")
*/
Expand Down Expand Up @@ -165,7 +189,6 @@ private function bulkPrint($object, $products) {
}

/**
* @Route("/new/{purchaseOrderId}/{salesOrderId}/{productTypeId}", name="product_new")
* @Route("/edit/{id}/{success}", name="product_edit")
* @Route("/editsub/{refId}/{id}", name="product_subedit")
*/
Expand Down Expand Up @@ -233,7 +256,7 @@ public function editAction(Request $request, $id = 0, $purchaseOrderId = 0, $sal
{
$file = new ProductAttributeFile($product, $v, $k);
$em->persist($file);
$em->flush($file);
$em->flush();

$val = $r->getValue() ? $r->getValue() . "," . $file->getId() : $file->getId();
$r->setValue($val);
Expand Down
48 changes: 40 additions & 8 deletions src/AppBundle/Controller/VueProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
namespace AppBundle\Controller;

use AppBundle\Entity\Product;
use AppBundle\Entity\ProductType;
use AppBundle\Entity\PurchaseOrder;
use AppBundle\Entity\SalesOrder;
use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use AppBundle\Entity\ProductAttributeRelation;

/**
* This controller will replace the ProductController gradually
Expand Down Expand Up @@ -92,20 +94,50 @@ public function editAction(Request $request, $productId)
/** @var \AppBundle\Repository\ProductRepository */
$repo = $this->getDoctrine()->getRepository('AppBundle:Product');

if ($productId == 0)
/** @var Product */
$product = $repo->find($productId);

$repo->generateProductAttributeRelations($product);

return $product;
}

/**
* @Rest\Get("/new/{purchaseOrderId}/{salesOrderId}/{productTypeId}")
* @Rest\View(serializerGroups={"product:edit"})
*/
public function newAction(Request $request, $purchaseOrderId, $salesOrderId, $productTypeId)
{
$em = $this->getDoctrine()->getManager();

/** @var \AppBundle\Repository\ProductRepository */
$repo = $em->getRepository('AppBundle:Product');

$product = new Product();

if ($productTypeId > 0)
{
$product = new Product();
$product->setType($em->getReference(ProductType::class, $productTypeId));
}
else

if ($salesOrderId > 0 && $purchaseOrderId > 0) // backorder
{
/** @var Product */
$product = $repo->find($productId);
$repo->generateProductOrderRelation($product, $em->find(SalesOrder::class, $salesOrderId));
$repo->generateProductOrderRelation($product, $em->find(PurchaseOrder::class, $purchaseOrderId), 0);
}

elseif ($salesOrderId > 0) // repair order
{
$repo->generateProductOrderRelation($product, $em->find(SalesOrder::class, $salesOrderId));
}
elseif ($purchaseOrderId > 0) // normal purchase
{
$repo->generateProductOrderRelation($product, $em->find(PurchaseOrder::class, $purchaseOrderId));
}

$repo->generateProductAttributeRelations($product);

return $product;
}
}

/**
* @Rest\Get("/checklist/{productId}")
Expand Down
9 changes: 9 additions & 0 deletions src/AppBundle/Resources/views/Product/new.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

<div id="product-new"
data-purchaseorderid="{{ purchaseOrderId }}"
data-salesorderid="{{ salesOrderId }}"
data-producttypeid="{{ productTypeId }}"
></div>

{{ encore_entry_script_tags('product-new') }}

6 changes: 4 additions & 2 deletions src/AppBundle/Resources/views/PurchaseOrder/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@
{{ form_widget(form._token) }}
{{ form_end(form, {'render_rest': false}) }}

<div id="newProductModalContainer"></div>

{% endblock %}

{% block javascripts %}
Expand Down Expand Up @@ -265,10 +267,10 @@
$('select[name="purchase_order_form[newProduct]"]').change(function () {
if ($(this).val()) {
$("#modalOrderEditor .modal-content").load('{{ path('product_new', { 'purchaseOrderId': order.id }) }}/0/' + $(this).val(), function () {
$("#newProductModalContainer").load('{{ path('product_new', { 'purchaseOrderId': order.id }) }}/0/' + $(this).val(), function () {
focusBarcodeInput();
});
$("#modalOrderEditor").modal('show');
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/AppBundle/Resources/views/SalesOrder/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@
{{ form_widget(form._token) }}
{{ form_end(form, {'render_rest': false}) }}

<div id="newProductModalContainer"></div>

{% endblock %}

{% block javascripts %}
Expand Down Expand Up @@ -296,10 +298,9 @@
$('select[name="sales_order_form[newProduct]"]').change(function () {
if ($(this).val()) {
$("#modalOrderEditor .modal-content").load('{{ path('product_new', { 'purchaseOrderId': order.backingPurchaseOrder.id, 'salesOrderId': order.id }) }}/' + $(this).val(), function () {
$("#newProductModalContainer").load('{{ path('product_new', { 'purchaseOrderId': order.backingPurchaseOrder.id, 'salesOrderId': order.id }) }}/' + $(this).val(), function () {
focusBarcodeInput();
});
$("#modalOrderEditor").modal('show');
}
});
Expand All @@ -309,10 +310,9 @@
$('select[name="sales_order_form[newProduct]"]').change(function () {
if ($(this).val()) {
$("#modalOrderEditor .modal-content").load('{{ path('product_new', { 'purchaseOrderId': 0, 'salesOrderId': order.id }) }}/' + $(this).val(), function () {
$("#newProductModalContainer").load('{{ path('product_new', { 'purchaseOrderId': 0, 'salesOrderId': order.id }) }}/' + $(this).val(), function () {
focusBarcodeInput();
});
$("#modalOrderEditor").modal('show');
}
});
Expand Down
74 changes: 74 additions & 0 deletions src/AppBundle/Resources/vue/ProductNew/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<template>
<div>

<ModalEdit urlPrefix="../../"
:purchaseOrderId="purchaseOrderId" :salesOrderId="salesOrderId" :productTypeId="productTypeId"
:productStatuses="productStatuses" :locations="locations" :productTypes="productTypes"
/>

</div>
</template>

<script>
import ModalEdit from '../ProductStock/components/modals/ModalEdit.vue'
export default {
name: 'App',
components: { ModalEdit },
data() {
var dataElement = document.querySelector('div#product-new');
var purchaseOrderId = parseInt(dataElement.dataset.purchaseorderid);
var salesOrderId = parseInt(dataElement.dataset.salesorderid);
var productTypeId = parseInt(dataElement.dataset.producttypeid);
return {
purchaseOrderId,
salesOrderId,
productTypeId,
productId: null,
productStatuses: [],
productTypes: [],
locations: [],
}
},
computed: {
offset() {
return (this.page-1) * this.pageLength
},
pageCount() {
return Math.ceil(parseFloat(this.productCount) / this.pageLength)
},
},
mounted() {
this.loadMeta()
$('#modalEdit').modal('show')
},
methods: {
loadMeta() {
this.axios.get("../../vue/product/meta")
.then(response => {
this.productStatuses = response.data.productStatuses
this.productTypes = response.data.productTypes
this.locations = response.data.locations
})
},
closeModal() {
this.product=null
this.modal=null
$('.modal').modal('hide')
},
formattedPrice(product, withEuroSign) {
if (!product || !product.price) return ''
var price = parseFloat(product.price) / 100
price = price.toLocaleString('nl', {minimumFractionDigits: 2, maximumFractionDigits: 2})
return withEuroSign ? ''+price : price
}
}
}
</script>


8 changes: 8 additions & 0 deletions src/AppBundle/Resources/vue/ProductNew/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import App from './App.vue'

Vue.use(VueAxios, axios)

new Vue({ render: h => h(App) }).$mount('#product-new')
Loading

0 comments on commit a13919c

Please sign in to comment.