Giter VIP home page Giter VIP logo

ochoarobert1 / ccontrol Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 468 KB

Simple plugin for Client control, budgeting and invoice. Manage your business operations with ease.

Home Page: https://robertochoaweb.com/

License: GNU General Public License v2.0

PHP 48.77% CSS 0.04% JavaScript 1.55% Less 46.78% Hack 2.87%
automation freelance-platform plugin wordpress wordpress-plugin wordpress-plugin-development

ccontrol's Introduction

Robert Ochoa header

        

Hello there 👋

Soy un desarrollador web residenciado en Venezuela, especializado en soluciones WordPress / Woocommerce.

Productos Digitales de alta calidad desarrollados con un enfoque de ganancia orgánica.

Más de 6 años de experiencia, transformando negocios digitales y sirviendo a través de la web, me hacen condensar mi conocimiento en los siguientes renglones.

  • 💻 Desarrollo Web en WordPress > Tu solucion digital, lista para llevar en pocos días.
  • 🛒 Desarrollo de E-commerce > Tu tienda online adaptada a tu modelo de negocio.
  • 🔌 Desarrollo de Plugins en WordPress > Agreguemos a tu WordPress soluciones integrales para tu negocio.
  • 🖥️ Maquetado Web en HTML5 > Armemos ese diseño en una interfaz "Pixel Perfect".
  • 🌐 Posicionamiento SEO OnSite > Vamos a hacerte aparecer de primero en Google.

  • 🔭 Conocimiento: WordPress / Woocommerce / Vue.js / Nginx / PHP / Docker
  • 🌱 Aprendiendo: React / React Native

ccontrol's People

Contributors

ochoarobert1 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

ccontrol's Issues

automatically update Quotations post title based on the 'cliente_presupuesto'++date custom field

//------------------------------------------------------------------------------------
// Function to automatically update Quotations post title based on the 'cliente_presupuesto'++date custom field.
//------------------------------------------------------------------------------------
function update_cc_presupuesto_title_on_save( $post_id ) {
if ( 'cc_presupuestos' != get_post_type( $post_id ) ) return;

	remove_action('save_post', 'update_cc_presupuesto_title_on_save');
	
	$cliente_presupuesto_id = get_post_meta( $post_id, 'cliente_presupuesto', true );
	// Fetch the client name using the post ID
	$cliente_presupuesto_name = get_the_title( $cliente_presupuesto_id );
	
	$publish_date = get_the_date( 'Y-m-d', $post_id );
	
	$new_title = $cliente_presupuesto_name . ' - Quote: ' . $publish_date;
	
	wp_update_post( array(
		'ID'         => $post_id,
		'post_title' => $new_title,
		'post_name'  => sanitize_title($new_title)
	));
	
	add_action('save_post', 'update_cc_presupuesto_title_on_save');
}
add_action( 'save_post', 'update_cc_presupuesto_title_on_save' );

Function to automatically update post title based on the 'nombre_cliente' custom field.

// Function to automatically update post title based on the 'nombre_cliente' custom field.
function custom_field_as_post_title_for_clients( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( 'cc_clientes' != get_post_type( $post_id ) ) return;
$nombre_cliente = get_post_meta( $post_id, 'nombre_cliente', true );
if ($nombre_cliente && get_the_title($post_id) !== $nombre_cliente) {
remove_action('save_post', 'custom_field_as_post_title_for_clients');
wp_update_post( array(
'ID' => $post_id,
'post_title' => $nombre_cliente,
) );
add_action('save_post', 'custom_field_as_post_title_for_clients');
}
}
add_action( 'save_post', 'custom_field_as_post_title_for_clients' );

Dynamic Entries for the PDF Constructor

Having Dynamic entries from settings controller Instead of hard-coding values in your PDF constructor for things like images and text (Brand, address, etc.)

will see how to expand this further (when i have some time)

Invoice Total Calculations

<?php endif; ?>
			</div>

`

Invoice Total: 0

<script>
jQuery(document).ready(function($) {
// Function to format numbers with commas for thousands
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

            // Function to calculate and update the total price
            function calculateTotal() {
                var total = 0;
                $('input[name="item_factura_price[]"]').each(function() {
                    var price = parseFloat($(this).val()) || 0;
                    var qtySelector = $(this).closest('.row-postmeta-items').find('input[name="item_factura_qty[]"]');
                    var qty = parseInt(qtySelector.val()) || 0;
                    total += price * qty;
                });
                // Format the total with commas and update the text
                $('#totalPrice').text(numberWithCommas(total.toFixed(2)));
            }

            // Calculate total when the page loads
            calculateTotal();

            // Recalculate total whenever quantity or price fields change
            $(document).on('change', 'input[name="item_factura_qty[]"], input[name="item_factura_price[]"]', function() {
                calculateTotal();
            });

            // Also recalculate when items are added or removed
            $(document).on('click', '.item-factura-add, .item-factura-remove', function() {
                // Add a slight delay to allow the DOM to update
                setTimeout(calculateTotal, 100);
            });
        });
			
			</script>
		</div>
		`

automatically update Invoice post title based on the 'cliente_factura'+numero_factura+date

//------------------------------------------------------------------------------------
// Function to automatically update Invoice post title based on the 'cliente_factura'+numero_factura+date custom field.
//------------------------------------------------------------------------------------
function update_cc_invoice_title_on_save_with_total( $post_id ) {
if ( 'cc_invoices' != get_post_type( $post_id ) ) return;

	remove_action('save_post', 'update_cc_invoice_title_on_save_with_total');
	
	// Get metadata values
	$cliente_factura_id = get_post_meta( $post_id, 'cliente_factura', true );
	$numero_factura = get_post_meta( $post_id, 'numero_factura', true );
	$cliente_factura_name = get_the_title( $cliente_factura_id ); // Fetching the client name
	$items_factura = get_post_meta( $post_id, 'items_factura', true );
	
	// Calculate total from line items
	$total = 0;
	if (is_array($items_factura)) {
		foreach ($items_factura as $item) {
			$price = isset($item['item_factura_price']) ? floatval($item['item_factura_price']) : 0;
			$qty = isset($item['item_factura_qty']) ? intval($item['item_factura_qty']) : 0;
			$total += $price * $qty;
		}
	}
	
	$publish_date = get_the_date( 'Y-m-d', $post_id );
	$formatted_total = number_format($total, 2, '.', ','); // Format the total as needed
	
	$new_title = $cliente_factura_name . ' - Invoice: ' . $numero_factura . ' - Date: ' . $publish_date . ' - Total: ' . $formatted_total;
	
	// Update the post
	wp_update_post( array(
		'ID'         => $post_id,
		'post_title' => $new_title,
		'post_name'  => sanitize_title($new_title)
	));
	
	add_action('save_post', 'update_cc_invoice_title_on_save_with_total');
}
add_action( 'save_post', 'update_cc_invoice_title_on_save_with_total' );

Dashboard (Basic Facelift)

can be expanded further

public function ccontrol_dashboard() {
		// Prepare data for dashboard widgets
		$totalClients = $this->ccontrol_total_clients();
		$totalQuotes = $this->ccontrol_total_quotes();
		$totalInvoices = $this->ccontrol_total_invoices();
		
		// Dashboard title and description
		$pluginDirUrl = esc_url(plugin_dir_url(dirname(__FILE__, 2)) . 'ccontrol/assets/images/icon_contacts.png');
		$adminPageTitle = esc_html(get_admin_page_title());
		$clientsIconUrl = esc_url(plugin_dir_url(dirname(__FILE__, 2)) . 'ccontrol/assets/images/icon_contacts.png');
		// Combined HTML output
		$html = <<<HTML
<div class="wrap">
    <div style="display: flex; align-items: center; justify-content: start; gap: 20px; margin-bottom: 20px;">
        <!-- Column 1: Image -->
        <div>
            <img src="{$pluginDirUrl}" alt="Contacts Icon" style="width: 64px;">
        </div>
        
        <!-- Column 2: Title and Description -->
        <div>
            <h1>{$adminPageTitle}
                <br>
                <small style="font-size: 12px; color: darkgray; display: block">
                    Manage your Business Operations with Ease
                </small>
            </h1>
        </div>
    </div>
    <style>
    .dashboard-widgets {
    display: flex;
    gap: 20px;
}

.dashboard-widget {
    background: #fff;
    border: 1px solid #ddd;
    padding: 20px;
    width: calc(33.333% - 20px);
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
        --bs-card-spacer-y: 1.5rem;
--bs-card-spacer-x: 1.5rem;
}

.w-100 {
width: 100% !important;
}

</style>

Total Clients

{$totalClients}

Total Quotations

{$totalQuotes}

Total Invoices

{$totalInvoices}

</div>

HTML;

		echo $html;
	}

adding a client and CPT issues

CPT is designed in a way to force the use of title in your case you need the client name and the title so you would end up entering the data twice which is a bit of a double effort to be frank.
I have added a small plugin that will allow you to enter the client name and have it do the title automatically.

/**
 * Plugin Name: CC Clients Customizations
 * Description: Customizes the CC Clients post type, setting post titles automatically from the 'nombre_cliente' custom field.
 * Version: 1.0
 * Author: Tarek Tarabichi
 */

// Function to automatically update post title based on the 'nombre_cliente' custom field.
function custom_field_as_post_title_for_clients( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( 'cc_clientes' != get_post_type( $post_id ) ) return;
$nombre_cliente = get_post_meta( $post_id, 'nombre_cliente', true );
if ($nombre_cliente && get_the_title($post_id) !== $nombre_cliente) {
remove_action('save_post', 'custom_field_as_post_title_for_clients');
wp_update_post( array(
'ID' => $post_id,
'post_title' => $nombre_cliente,
) );
add_action('save_post', 'custom_field_as_post_title_for_clients');
}
}
add_action( 'save_post', 'custom_field_as_post_title_for_clients' );

// Function to automatically update Invoice post title based on the 'cliente_factura'+numero_factura+date custom field.
function update_cc_invoice_title_on_save( $post_id ) {
if ( 'cc_invoices' != get_post_type( $post_id ) ) return;

	// Avoid recursion
	remove_action('save_post', 'update_cc_invoice_title_on_save');
	
	// Get metadata values
	$cliente_factura_id = get_post_meta( $post_id, 'cliente_factura', true );
	$numero_factura = get_post_meta( $post_id, 'numero_factura', true );
	
	// Fetch the client's name using the ID
	$cliente_factura_name = get_the_title( $cliente_factura_id ); // Assuming it's a post reference
	
	// Fetch other necessary values similarly
	// For example, if numero_factura needs conversion from ID to value, perform it here
	
	$publish_date = get_the_date( 'Y-m-d', $post_id ); // Format as needed
	
	$new_title = $cliente_factura_name . ' - ' . $numero_factura . ' - ' . $publish_date;
	
	// Update the post
	wp_update_post( array(
		'ID'         => $post_id,
		'post_title' => $new_title,
		'post_name'  => sanitize_title($new_title) // Update slug
	));
	
	// Re-hook this function
	add_action('save_post', 'update_cc_invoice_title_on_save');
}
add_action( 'save_post', 'update_cc_invoice_title_on_save' );

// Hook into the save action.
add_action( 'save_post', 'update_cc_invoice_title_on_save' );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.